forked from yllhwa/RSSWorker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.js
42 lines (38 loc) · 1013 Bytes
/
worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Hono } from 'hono';
import { basicAuth } from 'hono/basic-auth';
import { cors } from 'hono/cors';
import indexHtml from './html/index.html';
import notFoundHtml from './html/404.html';
import errorHtml from './html/err.html';
import robotsTxt from './robots.txt';
import route from './route';
const app = new Hono();
app.route('/rss', route);
app.get('/', (ctx) => {
return ctx.html(indexHtml);
});
app.get('robots.txt', (ctx) => {
return ctx.text(robotsTxt);
});
app.get('/debug', (ctx) => {
return ctx.json(ctx.req.raw?.cf);
});
app.notFound((ctx) => {
return ctx.html(notFoundHtml);
});
app.onError((err, c) => {
let stack_str = err.stack;
let stack_arr = stack_str.split('\n').join('<br>');
let result = errorHtml.replace('{ERROR_MESSAGE}', `${err}`);
result = result.replace('{ERROR_STACK}', `${stack_arr}`);
return c.html(result, 500);
});
// app.use(
// '/*',
// basicAuth({
// username: 'user',
// password: 'password',
// })
// );
app.use('/*', cors());
export default app;