Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support deployment to Vercel #14918

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ yarn.lock
yarn-error.log

scripts/twitter-token/accounts.*

.next
6 changes: 6 additions & 0 deletions app/api/[[...route]]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import app from '@/app';
import { handle } from 'hono/vercel';

app.basePath('/api');

export const GET = handle(app);
3 changes: 3 additions & 0 deletions app/default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Default() {
return null;
}
7 changes: 7 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html>
<body className="bg-white">{children}</body>
</html>
);
}
21 changes: 20 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
presets: [
[
'next/babel',
{
'preset-react': {
throwIfNamespace: false,
},
},
],
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
'@babel/preset-typescript',
],
plugins: ['@babel/plugin-transform-private-methods'],
};
10 changes: 5 additions & 5 deletions lib/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { compress } from 'hono/compress';
import mLogger from '@/middleware/logger';
import cache from '@/middleware/cache';
import template from '@/middleware/template';
import sentry from '@/middleware/sentry';
// import sentry from '@/middleware/sentry';
import accessControl from '@/middleware/access-control';
import debug from '@/middleware/debug';
import header from '@/middleware/header';
Expand All @@ -16,7 +16,7 @@ import { jsxRenderer } from 'hono/jsx-renderer';

import logger from '@/utils/logger';

import { notFoundHandler, errorHandler } from '@/errors';
// import { notFoundHandler, errorHandler } from '@/errors';
import registry from '@/registry';
import api from '@/api';

Expand All @@ -36,7 +36,7 @@ app.use(jsxRenderer(
}
));
app.use(mLogger);
app.use(sentry);
// app.use(sentry);
app.use(accessControl);
app.use(debug);
app.use(template);
Expand All @@ -48,7 +48,7 @@ app.use(cache);
app.route('/', registry);
app.route('/api', api);

app.notFound(notFoundHandler);
app.onError(errorHandler);
// app.notFound(notFoundHandler);
// app.onError(errorHandler);

export default app;
4 changes: 2 additions & 2 deletions lib/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ for (const namespace in namespaces) {
const wrapedHandler: Handler = async (ctx) => {
if (!ctx.get('data')) {
if (typeof namespaces[namespace].routes[path].handler !== 'function') {
const { route } = await import(`./routes/${namespace}/${namespaces[namespace].routes[path].location}`);
namespaces[namespace].routes[path].handler = route.handler;
// const { route } = await import(`./routes/${namespace}/${namespaces[namespace].routes[path].location}`);
// namespaces[namespace].routes[path].handler = route.handler;
}
ctx.set('data', await namespaces[namespace].routes[path].handler(ctx));
}
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ export { default as rss3Ums } from '@/views/rss3-ums';
export { default as json } from '@/views/json';
export { default as RSS } from '@/views/rss';
export { default as Atom } from '@/views/atom';
export { default as art } from 'art-template';

const mockArt = () => '';
export { mockArt as art };
5 changes: 5 additions & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
6 changes: 6 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
};

export default nextConfig;
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"build:docs": "tsx scripts/workflow/build-docs.ts",
"dev": "cross-env NODE_ENV=dev tsx watch --no-cache lib/index.ts",
"dev:cache": "cross-env NODE_ENV=production tsx watch lib/index.ts",
"dev:nextjs": "next dev",
"build:nextjs": "next build",
"start:nextjs": "next start",
"format": "eslint --cache --fix \"**/*.{ts,js,yml}\" && prettier \"**/*.{ts,js,json}\" --write",
"format:check": "eslint --cache \"**/*.{ts,js,yml}\" && prettier \"**/*.{ts,js,json}\" --check",
"format:staged": "lint-staged",
Expand Down Expand Up @@ -92,6 +95,7 @@
"mailparser": "3.6.9",
"markdown-it": "14.1.0",
"module-alias": "2.2.3",
"next": "14.1.4",
"notion-to-md": "3.1.1",
"oauth-1.0a": "2.2.6",
"ofetch": "1.3.4",
Expand All @@ -105,6 +109,8 @@
"puppeteer-extra-plugin-user-preferences": "2.4.1",
"query-string": "9.0.0",
"re2js": "0.4.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"rfc4648": "1.5.3",
"rss-parser": "3.13.0",
"sanitize-html": "2.13.0",
Expand All @@ -125,6 +131,7 @@
"zod": "3.22.4"
},
"devDependencies": {
"@babel/plugin-transform-private-methods": "7.24.1",
"@babel/preset-env": "7.24.3",
"@babel/preset-typescript": "7.24.1",
"@microsoft/eslint-formatter-sarif": "3.0.0",
Expand All @@ -145,6 +152,8 @@
"@types/markdown-it": "13.0.7",
"@types/module-alias": "2.0.4",
"@types/node": "20.11.30",
"@types/react": "18.2.67",
"@types/react-dom": "18.2.22",
"@types/request-promise-native": "1.0.21",
"@types/sanitize-html": "2.11.0",
"@types/supertest": "6.0.2",
Expand Down