refactor: reorganize gateway routes under /api/ prefix #183
Reference in New Issue
Block a user
Delete Branch "feat/177-gateway-route-reorg"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Gateway API 路由重组,统一归到
/api/前缀下。Why
原来
/register、/endpoints散落在根路径,管理接口和代理转发混在一起不够清晰。Changes
packages/workflow-gateway/src/index.ts
POST /register→POST /api/gateway/registerDELETE /register/:name→DELETE /api/gateway/register/:nameGET /endpoints→GET /api/gateway/endpointsALL /api/:agent/*→ALL /api/agents/:agent/*/healthz保留根级别packages/cli-workflow/src/commands/serve/tunnel.ts
packages/workflow-dashboard/src/api.ts
listAgents()→/api/gateway/endpointsagentBase()→/api/agents/:agentRef
Closes #177, closes #178, closes #179
路由重组逻辑清晰 👍 两个问题需要处理:
1. 多余的 lockfile
PR 新增了两个 lockfile:
pnpm-lock.yaml(根目录)packages/workflow-gateway/pnpm-lock.yamlmonorepo workspace 模式下,子包不应有独立 lockfile。根目录的 lockfile 如果之前就有应该只是更新而不是新增。请确认这两个文件是否应该在 .gitignore 里,或者是误提交。
2. auth skip 匹配过于宽泛
这会跳过所有以
/api/gateway/register开头的路径的 dashboard auth。当前因为 register/unregister 都用 GATEWAY_SECRET 做独立鉴权所以没问题,但startsWith是个隐患——未来如果在这个前缀下加了需要 dashboard auth 的路由会被静默跳过。建议改成精确匹配:
或者更干净的做法:把 gateway 路由拆到单独的 Hono group,group 级别用 GATEWAY_SECRET 中间件,就不需要在 dashboard auth 里做排除了。
两个问题都修好了 ✅
Hono group 方案很干净:gateway 管理路由独立成 sub-app,各路由自带 auth(register/unregister 用 GATEWAY_SECRET,endpoints 用 dashboard auth),proxy 路由也内联 dashboard auth。不再有全局中间件 + 例外的 pattern。lockfile 也清掉了。LGTM 🚀