Skip to content

配置了 api.apiPath 时,rest 的 9 条 direct-mount 路由挂在 {basePath}/{version} 而不是 {apiPath} #6306

Description

@qq9340100

现象

RestServer.getApiBasePath()rest-api-plugin.ts 的 direct-mount registrar 各自算了一次 API base,两者只在 apiPath 未设时相等:

  • packages/rest/src/rest-server.tsgetApiBasePath() 返回 api.apiPath ?? \${api.basePath}/${api.version}``;
  • packages/rest/src/rest-api-plugin.tsconst versionedBase = \${basePath}/${version}`(**不读 apiPath**),供 packages.(4 条)与 datasources/:name/external/`(5 条)两个 direct-mount registrar 使用。

于是设置了 api.apiPath 的部署上,route-manager 面整体迁到 {apiPath},而这 9 条 direct-mount 路由留在 /api/v1/...:同一部署两个 API 前缀,{apiPath}/openapi.jsonisUnderBase 过滤把这 9 条排除在文档之外。

复现

apiPath 无 authoring 路径(defineStack({server:{api:…}}) 被 strict 块 loud 拒绝,os serve 只转发两个 scoping 键),仅程序化 embedder 直接组合 createRestApiPlugin 可达:

createRestApiPlugin({ api: { api: { apiPath: '/backend/api/v9' } } })

启动后枚举挂载:route-manager 面全部在 /backend/api/v9/...packages.* / datasources/:name/external/* 仍在 /api/v1/...GET {apiPath}/packages 404,GET /api/v1/packages 200。

裁定(maintainer,2026-08-07 / 2026-08-08)

Option 1 —— 单一真相源:direct-mount registrar 消费 RestServer.getApiBasePath() 的同一个 base(thread 该值,不复制 ?? 表达式),9 条路由跟随 apiPath。不做兼容双挂载。

落地顺序按路线 B:先 #6633(discovery 通告 routes.packages / routes.datasources,且与挂载同源;SDK 从通告派生 base),再移动本卡的 9 条路由 —— 前置件已由 PR #6712 合入 main

验收

  • 设置 apiPath 时,9 条 direct-mount 路由在 {apiPath} 下应答,旧 /api/v1/... 不再服务;
  • {apiPath}/openapi.json 列出这 9 条;
  • /discoveryroutes.packages / routes.datasources 按构造跟随(同源投影,通告侧无需改动);
  • 默认配置(未设 apiPath)逐字节不变。

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions