gitlab_monitor/index.ts
zhaoyingbo 35bd784e6a
Some checks failed
CI Monitor CI/CD / build-image (push) Successful in 33s
CI Monitor MIflow / build-image (push) Successful in 37s
CI Monitor CI/CD / deploy (push) Failing after 1m5s
chore: 修改项目名
2024-07-26 09:20:53 +00:00

33 lines
986 B
TypeScript

import { manageCIMonitorReq } from "./routes/ci"
import { manageGitlabEventReq } from "./routes/event"
import initSchedule from "./schedule"
import netTool from "./service/netTool"
// 启动定时任务
initSchedule()
const server = Bun.serve({
async fetch(req) {
try {
const url = new URL(req.url)
const prefix = "/gitlab_monitor"
// 根路由
if (url.pathname === `${prefix}/`)
return netTool.ok("hello, glade to see you!")
// CI 监控
if (url.pathname === `${prefix}/ci`) return manageCIMonitorReq(req)
// Gitlab 事件
if (url.pathname === `${prefix}/event`) return manageGitlabEventReq(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}`)