import logger from "@egg/logger" import initAppConfig from "./constant/config" import { initSchedule } from "./schedule" import genContext from "./utils/genContext" initSchedule() await initAppConfig() const bunServer = Bun.serve({ async fetch(req, server) { // 设置超时时间 server.timeout(req, 30) // 生成上下文 const ctx = await genContext(req) const { path, genResp, logger } = ctx if (path.exact("/")) { logger.info(`${req.method} ${req.url}`) logger.debug(`req body: ${ctx.text}`) logger.debug(`req query: ${ctx.searchParams.toString()}`) } // 逻辑处理 try { // 健康检查 if (path.full("/health")) return genResp.healthCheck() // 其他 return genResp.healthCheck("hello, there is egg, glade to serve you!") } catch (error: any) { // 错误处理 logger.error(error.message) return genResp.serverError(error.message || "server error") } }, error(error) { logger.error(`Error: ${error}`) logger.error(`Stack: ${error.stack}`) return new Response("Internal Error", { status: 500 }) }, port: 3000, }) logger.info(`Listening on ${bunServer.hostname}:${bunServer.port}`) // // 关闭数据库连接 // process.on("SIGINT", async () => { // await prisma.$disconnect() // process.exit(0) // })