| import { serve } from '@hono/node-server'; |
| import { serveStatic } from '@hono/node-server/serve-static'; |
| import { Hono } from 'hono'; |
| import { configureTelegramWebhook, identityMiddleware, paywallGate } from './platform'; |
| import { api } from './routes/api'; |
| import { agentLinkApi, agentLinkExternal } from './routes/agentLink'; |
| import { chat } from './routes/chat'; |
| import { pass } from './routes/pass'; |
| import { telegram } from './routes/telegram'; |
|
|
| const app = new Hono(); |
|
|
| app.use('/api/*', identityMiddleware); |
| app.use('/api/*', paywallGate); |
|
|
| app.route('/api', pass); |
| app.route('/api', chat); |
| app.route('/api', api); |
| app.route('/api', agentLinkApi); |
| app.route('/external', agentLinkExternal); |
| app.route('/telegram', telegram); |
|
|
| const CLIENT_ROOT = './dist/client'; |
| |
| |
| app.use('/*', async (c, next) => { |
| await next(); |
| const requestPath = c.req.path; |
| if (requestPath === '/' || requestPath.endsWith('.html')) { |
| c.res.headers.set('Cache-Control', 'no-cache'); |
| } else if (requestPath.startsWith('/assets/')) { |
| c.res.headers.set('Cache-Control', 'public, max-age=31536000, immutable'); |
| } else if (requestPath.startsWith('/assets_px/') || requestPath.startsWith('/assets_masks/')) { |
| c.res.headers.set('Cache-Control', 'public, max-age=604800'); |
| } |
| }); |
| app.get('/', serveStatic({ path: `${CLIENT_ROOT}/splash.html` })); |
| app.use('/*', serveStatic({ root: CLIENT_ROOT })); |
|
|
| const port = Number(process.env.PORT ?? 7860); |
| serve({ fetch: app.fetch, port }, (info) => { |
| console.log(`WEED-SIM server listening on :${info.port}`); |
| void configureTelegramWebhook(); |
| }); |
|
|