28 lines
765 B
TypeScript
28 lines
765 B
TypeScript
import { manageCIMonitorReq } from "./routes/ci"
|
|
import initSchedule from "./schedule"
|
|
import netTool from "./service/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!")
|
|
// CI 监控
|
|
if (url.pathname === "/ci") return manageCIMonitorReq(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}`)
|