egg_server/index.ts
zhaoyingbo dab5b18276
All checks were successful
Egg CI/CD / build-image (push) Successful in 38s
Egg CI/CD / deploy (push) Successful in 1m19s
feat: 修改请求report的方式为完整的Body
2024-05-24 12:01:51 +00:00

27 lines
831 B
TypeScript

import { manageBotReq } from "./routes/bot";
import { manageMessageReq } from "./routes/message";
import { initSchedule } from "./schedule";
initSchedule();
Bun.serve({
async fetch(req) {
try {
const url = new URL(req.url);
// 根路由
if (url.pathname === "/") return new Response("hello, glade to see you!");
// 机器人
if (url.pathname === "/bot") return await manageBotReq(req);
// 消息代理发送
if (url.pathname === "/message") return await manageMessageReq(req);
// 其他
return new Response("hello, glade to see you!");
} catch (error: any) {
// 错误处理
console.error("🚀 ~ serve ~ error", error);
return new Response(error.message || "server error", { status: 500 });
}
},
port: 3000,
});