freshyo/apps/backend/worker.ts
2026-03-27 18:47:12 +05:30

18 lines
482 B
TypeScript

import type { ExecutionContext, D1Database } from '@cloudflare/workers-types'
export default {
async fetch(
request: Request,
env: Record<string, string> & { DB?: D1Database },
ctx: ExecutionContext
) {
;(globalThis as any).ENV = env
const { createApp } = await import('./src/app')
const { initDb } = await import('./src/dbService')
if (env.DB) {
initDb(env.DB)
}
const app = createApp()
return app.fetch(request, env, ctx)
},
}