feat(express): derive api.<bare-domain> for OpenAPI servers.url#3770
Conversation
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.
|
Warning Review limit reached
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
computeOpenApiServerUrland use it ininitSwaggerforspec.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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Summary
computeOpenApiServerUrl(domain)as a named pure export fromlib/services/express.jsconfig.domainis a bare host (e.g.trawl.me), the OpenAPIservers.urlnow correctly resolves tohttps://api.trawl.meinstead of the frontend hostname verbatimhttp://...orhttps://...) are returned unchangedWhy
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 prependshttps://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:3000→https://api.localhost:3000) acknowledged —config.domainin 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 passnpm run lint→ cleanNODE_ENV=test npm run test:coverage -- --testPathPatterns='unit'→ 1680 tests pass, coverage thresholds metDEVKIT_NODE_domain=trawl.me→GET /api/spec.jsonreturns"servers":[{"url":"https://api.trawl.me"}]✅