Skip to content

Dashboard admin API 'auto' port ignores window.location.port #3979

@acquiroKenan

Description

@acquiroKenan

Describe the bug
When the Vendure react dashboard is configured with api.host = 'auto' and api.port = 'auto',
local development requests drop the port even if the dashboard is loaded at http://
localhost:3000. All admin API calls go to http://localhost/admin-api (no :3000), causing
ERR_CONNECTION_REFUSED. Production hides the issue if the ALB runs on port 80/443.

To Reproduce

  1. Run Vendure + the dashboard locally on port 3000 (standard dev setup).
  2. Build the dashboard with api: { host: 'auto', port: 'auto' } (default behavior).
  3. Open http://localhost:3000/dashboard.
  4. Try to log in; network tab shows admin API POSTs to http://localhost/admin-api.

Expected behavior
When the dashboard is served from http://localhost:3000, admin API calls should target http://
localhost:3000/admin-api (matching window.location.port).

Actual behavior
Requests omit the port and hit http://localhost/admin-api, which fails with
ERR_CONNECTION_REFUSED.

Screenshots/Videos
(Attach a browser network screenshot showing the missing port.)

Error logs

POST http://localhost/admin-api?languageCode=en net::ERR_CONNECTION_REFUSED

Environment

  • @vendure/core version: 3.5.1 (dashboard package 3.5.1)
  • Node.js version: 24.x (reproduced on both)
  • Database: Postgres (not relevant)
  • OS: macOS
  • Browser: Chrome 142
  • Package manager: pnpm 10

Configuration

  // In apps/vendure/vite.config.mts
  vendureDashboardPlugin({
    vendureConfigPath: './src/vendure-config.ts',
    api: { host: 'auto', port: 'auto', adminApiPath: 'admin-api' },
  })

Minimal reproduction
Vendure repo with default dashboard config; run pnpm dev and open the dashboard at http://
localhost:3000/dashboard. No extra steps needed.

Workaround
Explicitly set api.port to the numeric port (e.g., { host: 'auto', port: 3000 }) or patch
getApiBaseUrl() to append window.location.port when port === 'auto'.

Additional context

  • Bug occurs consistently in local dev; production ALB (port 80/443) masks it.
  • Root cause: packages/dashboard/src/lib/utils/config-utils.ts#getApiBaseUrl() ignores
    window.location.port when uiConfig.api.port === 'auto'. It only appends a port if the config
    provides a numeric value. Appending window.location.port when it’s non-empty would fix the issue.
  • Where the behavior of 'auto' is promised:
    * The port of the Vendure server which the admin UI will be making API calls
  • Where the implementation of 'auto' fails to match docs:
    const portPart = uiConfig.api.port !== 'auto' ? `:${uiConfig.api.port}` : '';

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions