egg_server/index.ts
zhaoyingbo 6e65581bbf
All checks were successful
Egg CI/CD / build-image (push) Successful in 32s
Egg CI/CD / deploy (push) Successful in 37s
feat: 接入lint 和 husky
2024-07-25 01:48:22 +00:00

37 lines
1.2 KiB
TypeScript

import { manageBotReq } from "./routes/bot"
import { manageMessageReq } from "./routes/message"
import { manageMicroAppReq } from "./routes/microApp"
import { manageSheetReq } from "./routes/sheet"
import { initSchedule } from "./schedule"
import netTool from "./services/netTool"
initSchedule()
const server = Bun.serve({
async fetch(req) {
try {
const url = new URL(req.url)
// 根路由
if (url.pathname === "/") return netTool.ok("hello, glade to see you!")
// 机器人
if (url.pathname === "/bot") return await manageBotReq(req)
// 消息代理发送
if (url.pathname === "/message") return await manageMessageReq(req)
// 表格代理操作
if (url.pathname === "/sheet") return await manageSheetReq(req)
// 小程序
if (url.pathname.startsWith("/micro_app"))
return await manageMicroAppReq(req)
// 其他
return netTool.ok("hello, glade to see you!")
} catch (error: any) {
// 错误处理
console.error("🚀 ~ serve ~ error", error)
return netTool.serverError(error.message || "server error")
}
},
port: 3000,
})
console.log(`Listening on ${server.hostname}:${server.port}`)