fix(agent-bff): publish BFF_PUBLIC_URL as the openapi server url - #1866
fix(agent-bff): publish BFF_PUBLIC_URL as the openapi server url#1866Tonours wants to merge 7 commits into
Conversation
3 new issues
|
|
Coverage Impact This PR will not change total coverage. Modified Files with Diff Coverage (3)
🛟 Help
|
nbouliol
left a comment
There was a problem hiding this comment.
BFF_PUBLIC_URL is missing from .env.example, which lists the other optional BFF vars, and the forest-bff openapi export section of the README doesn't point at it — that export being the case the variable exists for.
|
Both added.
The
I also widened the env-table row, which said only "a malformed value fails the boot" and did not name the two rejections that matter: a URL carrying credentials would publish them to every reader of the document, and anything behind a |
|
The credential check I added last push did not hold. Fixed properly now. It was a raw-string regex, So The check now runs on the parsed URL, which is the only thing that agrees with the validator: const url = new URL(value);
if (url.username !== '' || url.password !== '') throw …;
return url.href.replace(/\/+$/, '');Emitting Four bypass forms added to the rejection table, plus a canonicalisation case. The |

fixes PRD-1109
What changed
Optional
BFF_PUBLIC_URLnow carries the deployment's external base URL intoservers[0].urlof every document shape: the generic document, the served unfolded document, and theforest-bff openapiexport. Unset,servers[0].urlstays/. A malformed value fails the boot. Trailing slashes, query strings, and fragments are rejected, because generated clients concatenateservers[0].url + pathand anything behind a?or#swallows the path.Why these choices
@hey-api/openapi-ts(the reference generator intest/openapi/openapi-generated-client.test.ts) returns no base URL at all when a server url holds a{variable}. The/it resolves today is worth more than nothing.Hostheader would end up in every other caller's document.FOREST_SERVER_URL. That one points at the Forest SaaS API, not at this BFF./on purpose. Per OAS, a relative server url resolves against the retrieval url, so Swagger UI or Postman importing the served document resolves the right host today. Only the offline export has no origin to resolve against, and that is the caseBFF_PUBLIC_URLexists for.How to test
yarn workspace @forestadmin/agent-bff testpasses 79 suites / 1363 tests, lint and build are clean. New cases cover parsing (valid, malformed, trailing slash, query, fragment, unset) andservers[0].urlin the document builder, the served route, and both export branches.Known limitation
Without
BFF_PUBLIC_URL, a client generated from the offline export still has no base URL. The fallback server entry names the variable to set.Definition of Done
General
Security