Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 5, 2025

When BASE_PATH is configured (e.g., BASE_PATH=/mcphub/), login fails in development because the Vite proxy doesn't match BASE_PATH-prefixed requests, and trailing slashes create invalid double-slash routes.

Changes

  • Backend (src/config/index.ts): Normalize BASE_PATH by stripping trailing slashes
  • Frontend (frontend/vite.config.ts): Generate Vite proxy rules dynamically from BASE_PATH environment variable
  • Tests (tests/integration/base-path-routes.test.ts): Verify BASE_PATH normalization and routing behavior
  • Docs (docs/BASE_PATH_CONFIGURATION.md): Usage guide with Docker/nginx examples

Implementation

// Backend: Normalize BASE_PATH
const normalizeBasePath = (path: string): string => 
  path ? path.replace(/\/+$/, '') : '';

// Frontend: Dynamic proxy from BASE_PATH
const env = loadEnv(mode, path.resolve(__dirname, '..'), '');
const basePath = env.BASE_PATH?.replace(/\/+$/, '') || '';
const proxyConfig = ['/api', '/config', '/public-config', '/health', '/oauth']
  .reduce((acc, path) => ({ ...acc, [basePath + path]: { target: 'http://localhost:3000' } }), {});

Fixes deployment under subdirectories and reverse proxies with path prefixes. Backward compatible with existing deployments.

Original prompt

This section details on the original issue you should resolve

<issue_title>本地开发模式配置BASE_PATH后无法登陆了</issue_title>
<issue_description>Bug Description / 问题描述
What happened? / 发生了什么?

Steps to Reproduce / 复现步骤

  1. 修改env文件,将BASE_PATH设置为"/mcphub/"
  2. 重启应用
  3. 发现登陆异常

Expected Behavior / 预期行为
希望能正常登陆

Environment / 运行环境

  • Running on / 运行方式: [docker/npx/local / docker/npx/本地]
  • Version / 版本: 0.10.3

Screenshots / 截图
If relevant, add screenshots / 如果有帮助的话,请添加截图

Additional Info / 补充信息
F12调试发现配置了BASE_PATH后,/api/,/login/以及一些其他鉴权相关的url不会自动加上basepath前缀
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits November 5, 2025 11:07
- Normalize BASE_PATH by removing trailing slashes in backend config
- Update Vite dev server proxy to dynamically support BASE_PATH from env
- Add integration tests for BASE_PATH functionality
- All tests pass, build successful

Co-authored-by: samanhappy <[email protected]>
Copilot AI changed the title [WIP] Fix login issue when configuring BASE_PATH Fix BASE_PATH configuration breaking login in development mode Nov 5, 2025
Copilot AI requested a review from samanhappy November 5, 2025 11:18
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.

本地开发模式配置BASE_PATH后无法登陆了

2 participants