Skip to content

feat(express): derive api.<bare-domain> for OpenAPI servers.url#3770

Merged
PierreBrisorgueil merged 1 commit into
masterfrom
feat/promote-api-domain-prefix
Jun 1, 2026
Merged

feat(express): derive api.<bare-domain> for OpenAPI servers.url#3770
PierreBrisorgueil merged 1 commit into
masterfrom
feat/promote-api-domain-prefix

Conversation

@PierreBrisorgueil
Copy link
Copy Markdown
Contributor

Summary

  • Extracts computeOpenApiServerUrl(domain) as a named pure export from lib/services/express.js
  • When config.domain is a bare host (e.g. trawl.me), the OpenAPI servers.url now correctly resolves to https://api.trawl.me instead of the frontend hostname verbatim
  • Backward-compatible: full-URL domains (http://... or https://...) are returned unchanged
  • 5 unit tests covering: bare host, https URL, http URL, custom-subdomain URL, falsy fallback

Why

Every devkit downstream with a split frontend/backend topology (<bare>api.<bare>) was advertising the wrong API host in its OpenAPI spec. Trawl's production-validated pattern prepends https://api. when no scheme is present.

Promote-up from trawl_node (production-validated). Closes #3766.

Part of infra plan 2026-06-01-trawl-promote-up-followups.md, Task 1.

Phase 0 gate (pre-push critical-review via DeepSeek)

Verdict: OK with nits — 0 critical, 0 high. Medium: bare host:port edge case (e.g. localhost:3000https://api.localhost:3000) acknowledged — config.domain in practice is always a bare hostname or full URL; the fallback default covers the localhost case. Low: intentional behavioral change for bare-hostname downstreams (correct and expected). No blocking findings.

Test plan

  • NODE_ENV=test npm run test:unit -- lib/services/tests/express.openapi-servers → 5 tests pass
  • npm run lint → clean
  • NODE_ENV=test npm run test:coverage -- --testPathPatterns='unit' → 1680 tests pass, coverage thresholds met
  • Runtime: server started with DEVKIT_NODE_domain=trawl.meGET /api/spec.json returns "servers":[{"url":"https://api.trawl.me"}]

When config.domain is a bare host (e.g. trawl.me), the OpenAPI
servers.url previously pointed at the frontend host verbatim.

Extracts computeOpenApiServerUrl() — a pure named export that prepends
https://api. when the domain has no scheme, and returns the value
verbatim when it already starts with http(s)://. Backward-compatible
for all existing downstreams that set a full URL domain.

Promote-up from trawl_node (production-validated). Every devkit
downstream with a split frontend/backend topology (bare domain →
api.<bare>) now gets the correct OpenAPI host for free.

Tests: 5 unit cases covering bare host, https URL, http URL,
custom-subdomain URL, and falsy fallback.
Copilot AI review requested due to automatic review settings June 1, 2026 19:27
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Warning

Review limit reached

@PierreBrisorgueil, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 53 minutes and 34 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 29924152-6eb7-4f1b-ac8b-366759dedbd4

📥 Commits

Reviewing files that changed from the base of the PR and between 5604011 and 9c65788.

📒 Files selected for processing (2)
  • lib/services/express.js
  • lib/services/tests/express.openapi-servers.unit.tests.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/promote-api-domain-prefix

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
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Extracts a small pure helper computeOpenApiServerUrl(domain) from lib/services/express.js so that when config.domain is a bare host (e.g. trawl.me), the OpenAPI servers.url resolves to https://api.<domain> instead of advertising the frontend hostname. Full-URL domains (http(s)://...) are preserved verbatim, keeping behavior backward-compatible.

Changes:

  • Add exported computeOpenApiServerUrl and use it in initSwagger for spec.servers.
  • Add 5 unit tests covering bare host, http/https URLs, custom subdomain, and falsy fallback.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/services/express.js Adds computeOpenApiServerUrl helper and uses it to derive spec.servers[0].url.
lib/services/tests/express.openapi-servers.unit.tests.js New unit tests covering scheme-preserving and api. prepending behaviors.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.15%. Comparing base (7ed5291) to head (9c65788).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #3770       +/-   ##
===========================================
+ Coverage   59.43%   90.15%   +30.71%     
===========================================
  Files         151      151               
  Lines        4970     4977        +7     
  Branches     1577     1578        +1     
===========================================
+ Hits         2954     4487     +1533     
+ Misses       1491      385     -1106     
+ Partials      525      105      -420     
Flag Coverage Δ
integration 59.51% <100.00%> (+0.07%) ⬆️
unit 69.07% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7ed5291...9c65788. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@PierreBrisorgueil PierreBrisorgueil merged commit 7ae3664 into master Jun 1, 2026
9 checks passed
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.

feat(express): derive api.<bare-domain> for OpenAPI servers.url when domain is bare host

2 participants