feat: 优化路径工具函数
All checks were successful
Egg Server MIflow / build-image (push) Successful in 37s

This commit is contained in:
zhaoyingbo 2024-07-30 09:38:38 +00:00
parent c4c10f2ba0
commit f846b15451
2 changed files with 8 additions and 8 deletions

View File

@ -14,15 +14,15 @@ const server = Bun.serve({
// 打印当前路由
console.log("🚀 ~ serve ~ req.url", req.url)
// 路由处理
const { exactPath, startsWithPath } = makeCheckPathTool(req.url)
const { exactCheck, startsWithCheck } = makeCheckPathTool(req.url)
// 机器人
if (exactPath("/bot")) return await manageBotReq(req)
if (exactCheck("/bot")) return await manageBotReq(req)
// 消息代理发送
if (exactPath("/message")) return await manageMessageReq(req)
if (exactCheck("/message")) return await manageMessageReq(req)
// 表格代理操作
if (exactPath("/sheet")) return await manageSheetReq(req)
if (exactCheck("/sheet")) return await manageSheetReq(req)
// 小程序
if (startsWithPath("/micro_app")) return await manageMicroAppReq(req)
if (startsWithCheck("/micro_app")) return await manageMicroAppReq(req)
// 其他
return netTool.ok("hello, there is egg, glade to serve you!")
} catch (error: any) {

View File

@ -79,13 +79,13 @@ const manageBatchUser = async (req: Request) => {
* @returns
*/
export const manageMicroAppReq = async (req: Request) => {
const { exactPath } = makeCheckPathTool(req.url, "/micro_app")
const { exactCheck } = makeCheckPathTool(req.url, "/micro_app")
// 处理登录请求
if (exactPath("/login")) {
if (exactCheck("/login")) {
return manageLogin(req)
}
// 处理批量获取用户信息请求
if (exactPath("/batch_user")) {
if (exactCheck("/batch_user")) {
return manageBatchUser(req)
}
return netTool.ok()