Skip to content

Conversation

@SiebelsTim
Copy link
Contributor

@SiebelsTim SiebelsTim commented Nov 17, 2025

Description

When the API port is configured to be 'auto' (which is the default) and we are using a non-standard (443,80) port, we cannot login as the API client does not honor the port of the currently accessed page.

This is a regression introduced in #3919. The healthcheck endpoint did not respect window.location.port as it was building a relative URL. The extracted utility is always building an absolute URL and therefore needs to respect window.location.

Breaking changes

no, fixes regression.

Screenshots

You can add screenshots here if applicable.

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

Summary by CodeRabbit

  • Bug Fixes

    • Improved API base URL logic: when the API port is set to "auto", the app now uses the browser's current port when available, preventing mismatched connections and improving reliability.
  • Documentation

    • Added inline documentation clarifying how the API base URL and port are determined.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Nov 17, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
docs Ready Ready Preview Nov 24, 2025 9:50am
vendure-storybook Ready Ready Preview Comment Nov 24, 2025 9:50am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 17, 2025

Walkthrough

Rewrote getApiBaseUrl in config-utils.ts to use globalThis.location for deriving port when uiConfig.api.port === 'auto', adding JSDoc and a computed locationPortPart so the runtime location port is included if present; signature unchanged.

Changes

Cohort / File(s) Summary
API base URL port handling
packages/dashboard/src/lib/utils/config-utils.ts
Replaced window usage with globalThis; added JSDoc; introduced locationPortPart and updated logic so when uiConfig.api.port === 'auto' the function derives and includes globalThis.location.port (if non-empty) in the returned base URL; explicit ports remain unchanged.

Sequence Diagram(s)

sequenceDiagram
    participant UI as Dashboard UI
    participant Fn as getApiBaseUrl
    participant Loc as globalThis.location

    UI->>Fn: request API base URL (uiConfig)
    alt uiConfig.api.port == 'auto'
        Fn->>Loc: read port (globalThis.location.port)
        alt port present
            Loc-->>Fn: "<port>"
            Fn-->>UI: return scheme://host:<port>/path
        else port empty
            Loc-->>Fn: ""
            Fn-->>UI: return scheme://host/path
        end
    else explicit port provided
        Fn-->>UI: return scheme://host:<explicitPort>/path
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Small, single-file change with limited control-flow addition.
  • Review focus:
    • Ensure globalThis substitution is safe in all target runtimes.
    • Verify correct handling when location.port is empty or non-standard.
    • Confirm no callers assume the prior omitted-port behavior.

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing port:auto functionality for API requests in the dashboard, which directly addresses the regression mentioned in the PR.
Description check ✅ Passed The description includes all required sections from the template (Description, Breaking changes, Screenshots, Checklist) with the key sections appropriately filled out, explaining the regression and its fix.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e662704 and 9f24c38.

📒 Files selected for processing (1)
  • packages/dashboard/src/lib/utils/config-utils.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: michaelbromley
Repo: vendure-ecommerce/vendure PR: 3957
File: packages/create/src/create-vendure-app.ts:382-389
Timestamp: 2025-11-11T12:17:44.531Z
Learning: In the Vendure create CLI quick-start mode, the Dashboard is accessed at the same port as the Vendure server (e.g., `http://localhost:${port}/dashboard`), not at a separate port 3000.
🧬 Code graph analysis (1)
packages/dashboard/src/lib/utils/config-utils.ts (1)
packages/dashboard/src/lib/virtual.d.ts (1)
  • uiConfig (38-38)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: e2e tests (24.x, mysql)
  • GitHub Check: e2e tests (20.x, mysql)
  • GitHub Check: e2e tests (22.x, postgres)
  • GitHub Check: e2e tests (20.x, mariadb)
  • GitHub Check: e2e tests (20.x, postgres)
  • GitHub Check: unit tests (24.x)
  • GitHub Check: unit tests (20.x)
  • GitHub Check: build (20.x)
  • GitHub Check: unit tests (22.x)
  • GitHub Check: build (22.x)
  • GitHub Check: build (24.x)
  • GitHub Check: publish_install (ubuntu-latest, 24.x)
  • GitHub Check: publish_install (macos-latest, 20.x)
  • GitHub Check: publish_install (macos-latest, 24.x)
  • GitHub Check: publish_install (windows-latest, 20.x)
  • GitHub Check: publish_install (macos-latest, 22.x)
  • GitHub Check: publish_install (windows-latest, 24.x)
  • GitHub Check: publish_install (windows-latest, 22.x)
  • GitHub Check: publish_install (ubuntu-latest, 22.x)
  • GitHub Check: publish_install (ubuntu-latest, 20.x)

@michaelbromley
Copy link
Member

Thanks for the fix! Can you just take a look at the sonar cloud issues and fix? They are very minor.

@SiebelsTim
Copy link
Contributor Author

Sure! Wasn't sure if I'm supposed to migrate to this. I checked caniuse for globalThis and it seems pretty safe to use.

@sonarqubecloud
Copy link

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/dashboard/src/lib/utils/config-utils.ts (1)

3-8: JSDoc matches behavior; consider noting browser-location dependency.

The documentation accurately describes what getApiBaseUrl() does. For future maintainers (and to avoid confusion in any non-DOM/SSR context), you might optionally add a short note that 'auto' derives host/port from the current browser location (location), i.e. this utility is intended for the Dashboard runtime.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0026ffc and 6ac0849.

📒 Files selected for processing (1)
  • packages/dashboard/src/lib/utils/config-utils.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-11T12:17:44.531Z
Learnt from: michaelbromley
Repo: vendure-ecommerce/vendure PR: 3957
File: packages/create/src/create-vendure-app.ts:382-389
Timestamp: 2025-11-11T12:17:44.531Z
Learning: In the Vendure create CLI quick-start mode, the Dashboard is accessed at the same port as the Vendure server (e.g., `http://localhost:${port}/dashboard`), not at a separate port 3000.

Applied to files:

  • packages/dashboard/src/lib/utils/config-utils.ts
🧬 Code graph analysis (1)
packages/dashboard/src/lib/utils/config-utils.ts (1)
packages/dashboard/src/lib/virtual.d.ts (1)
  • uiConfig (38-38)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: publish_install (macos-latest, 22.x)
  • GitHub Check: publish_install (macos-latest, 20.x)
  • GitHub Check: e2e tests (24.x, sqljs)
  • GitHub Check: e2e tests (24.x, postgres)
  • GitHub Check: e2e tests (24.x, mysql)
  • GitHub Check: e2e tests (22.x, postgres)
  • GitHub Check: e2e tests (22.x, mariadb)
  • GitHub Check: e2e tests (22.x, sqljs)
  • GitHub Check: e2e tests (24.x, mariadb)
  • GitHub Check: e2e tests (22.x, mysql)
  • GitHub Check: e2e tests (20.x, postgres)
  • GitHub Check: e2e tests (20.x, mariadb)
  • GitHub Check: e2e tests (20.x, mysql)
  • GitHub Check: e2e tests (20.x, sqljs)
  • GitHub Check: build (20.x)
  • GitHub Check: unit tests (22.x)
  • GitHub Check: unit tests (20.x)
  • GitHub Check: unit tests (24.x)
  • GitHub Check: build (24.x)
  • GitHub Check: build (22.x)
🔇 Additional comments (1)
packages/dashboard/src/lib/utils/config-utils.ts (1)

13-16: Port handling for 'auto' correctly respects the current location (including standard ports).

Using globalThis.location for the host when uiConfig.api.host === 'auto' and the locationPortPart helper to conditionally append :${location.port} cleanly fixes the regression: non-standard ports are now honored, and standard ports (80/443) no longer produce a trailing colon. This aligns with the Dashboard running on the same port as the Vendure server in quick-start setups. Based on learnings, this behavior is exactly what we want.

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.

2 participants