Skip to content

fix(frontend): use relative baseURL in production, avoid hardcoded localhost#100

Open
JasonOA888 wants to merge 1 commit into666ghj:mainfrom
JasonOA888:fix/frontend-baseurl
Open

fix(frontend): use relative baseURL in production, avoid hardcoded localhost#100
JasonOA888 wants to merge 1 commit into666ghj:mainfrom
JasonOA888:fix/frontend-baseurl

Conversation

@JasonOA888
Copy link

Problem

Frontend baseURL defaults to http://localhost:5001 in all environments, causing:

  1. Users can only access from the machine running MiroFish
  2. Docker deployments with non-5001 ports fail
  3. Server deployments require frontend rebuild to change URL

Solution

Make baseURL environment-aware:

  • Production: Use relative path (empty string) for same-origin deployment
  • Development: Keep localhost:5001 default
  • Override: VITE_API_BASE_URL still takes highest priority
const getBaseURL = () => {
  if (import.meta.env.VITE_API_BASE_URL) {
    return import.meta.env.VITE_API_BASE_URL
  }
  if (import.meta.env.PROD) {
    return ''  // relative path in production
  }
  return 'http://localhost:5001'  // dev default
}

Testing

  • Dev: Works with localhost:5001
  • Prod (Docker): Works with any port mapping
  • Custom: Works with VITE_API_BASE_URL set

Fixes #93, related to #59, #57

…calhost

Previously baseURL defaulted to 'http://localhost:5001' in all environments,
causing issues when deployed on servers or Docker with port mapping.

Changes:
- Use relative path (empty string) in production for same-origin deployment
- Keep localhost:5001 default for development environment
- Still respects VITE_API_BASE_URL env var if set

Fixes 666ghj#93, related to 666ghj#59, 666ghj#57
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. enhancement New feature or request labels Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

frontend/src/api/index.js中的baseURL不应该硬编码

1 participant