Skip to content

fix(web): preserve nginx subpath prefix for api/runtime config#226

Open
dongmucat wants to merge 1 commit intomainfrom
fix/issue-223-nginx-prefix
Open

fix(web): preserve nginx subpath prefix for api/runtime config#226
dongmucat wants to merge 1 commit intomainfrom
fix/issue-223-nginx-prefix

Conversation

@dongmucat
Copy link
Copy Markdown
Collaborator

概述

修复 SkillHub 在 Nginx 子路径反向代理(如 /skill_hub)下 API 前缀失效与 runtime-config 加载路径错误的问题。

变更内容

后端实现

  • 无后端代码变更。
  • DB migration 变更:无。
  • API 契约变更:无。

前端实现

  • 修复 API URL 拼接逻辑,避免 new URL('/path', baseUrl) 覆盖 baseUrl 子路径前缀。
  • withBaseUrlbuildApiUrl 统一改为前缀保留拼接逻辑(prependApiBaseUrl)。
  • bootstrap 中 runtime 配置脚本改为基于 import.meta.url 解析,支持子路径部署下加载 runtime-config.js
  • 新增/更新单测覆盖:
    • apiBaseUrlhttps://api.example.com/skill_hub
    • apiBaseUrl/skill_hub
    • fetchText 请求路径前缀拼接

测试覆盖

  • 后端单测:无后端变更,未执行。
  • 前端单测:
    • cd web && pnpm vitest run src/api/client.test.ts
    • make test-frontend(172 files, 512 tests)
  • E2E 测试:
    • cd web && pnpm test:e2e(33 passed)
    • 结果目录:web/test-results/

质量门禁

  • make typecheck-web 通过(0 errors)
  • make lint-web 通过(0 errors, 0 warnings)
  • make test-frontend 通过
  • make test-backend-app 通过(如有后端变更)
  • Playwright E2E(web/e2e)关键路径通过(如有 UI 交互变更)
  • make generate-api 已执行且 schema.d.ts 已提交(如有 Controller 变更)

安全考虑

本次变更不涉及安全敏感内容。

相关 Issue

Closes #223

测试说明

本地验证步骤

  1. 配置运行时变量:SKILLHUB_WEB_API_BASE_URL=/skill_hub
  2. 通过 Nginx 子路径访问 SkillHub 页面(例如 https://<host>/skill_hub/)。
  3. 访问需要 API 请求的页面(登录态获取、列表页、详情页),确认请求路径为 /skill_hub/api/... 且可正常返回。

回归测试范围

  • API 请求基址拼接逻辑(withBaseUrlbuildApiUrl
  • runtime 配置加载流程(bootstrap
  • Nginx 子路径部署访问链路

截图/录屏(如有 UI 变更)

无 UI 视觉变更;E2E 产物见 web/test-results/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 无法通过nginx访问

1 participant