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 Cloudflare Workers #14917

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions lib/cf.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Hono } from 'hono';

import { compress } from 'hono/compress';
import mLogger from '@/middleware/logger';
import cache from '@/middleware/cache';
import template from '@/middleware/template';
import accessControl from '@/middleware/access-control';
import debug from '@/middleware/debug';
import header from '@/middleware/header';
import antiHotlink from '@/middleware/anti-hotlink';
import parameter from '@/middleware/parameter';
import { jsxRenderer } from 'hono/jsx-renderer';

import logger from '@/utils/logger';

import registry from '@/registry';
import api from '@/api';

process.on('uncaughtException', (e) => {
logger.error('uncaughtException: ' + e);
});

const app = new Hono();

app.use(compress());

app.use(jsxRenderer(
({ children }) => <>{children}</>,
{
docType: '<?xml version="1.0" encoding="UTF-8"?>',
stream: {}
}
));
app.use(mLogger);
app.use(accessControl);
app.use(debug);
app.use(template);
app.use(header);
app.use(antiHotlink);
app.use(parameter);
app.use(cache);

app.route('/', registry);
app.route('/api', api);

export default app;
2 changes: 1 addition & 1 deletion lib/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { fileURLToPath } from 'node:url';
import { serveStatic } from '@hono/node-server/serve-static';

import index from '@/routes/index';
import robotstxt from '@/routes/robots.txt';
import robotstxt from '@/routes/robots.txt.ts';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"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:cf": "wrangler dev lib/cf.tsx",
"deploy:cf": "wrangler deploy --minify lib/cf.tsx",
"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 @@ -121,6 +123,7 @@
"undici": "6.10.2",
"uuid": "9.0.1",
"winston": "3.13.0",
"wrangler": "3.36.0",
"xxhash-wasm": "1.0.2",
"zod": "3.22.4"
},
Expand Down
Loading
Loading