Repository navigation
feat(load-balancer): make the development provider URL configurable - #3232
Merged
Merged
Conversation
In development the widget looked for its provider at a hardcoded https://localhost:9229. That is right when the page and the provider share a machine and wrong as soon as they do not: a phone or an iOS simulator loading the demo over the LAN resolves localhost to itself, never reaches the provider, and reports the site key as unregistered. PROSOPO_PROVIDER_URL_DEVELOPMENT now overrides it. Unset, it still falls back to https://localhost:9229, so existing setups are unaffected. Staging and production resolve through their DNS-routed endpoints and ignore it. The override is read as a static process.env access so the frontend build can substitute it for a literal, and the endpoint map is resolved per call rather than once at module load. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The fixtures used a real LAN address from the machine they were written on. RFC 5737 reserves 192.0.2.0/24 and 198.51.100.0/24 for exactly this, and they cannot resolve to anything real. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was annoying
In development the widget looks for its provider at a hardcoded
https://localhost:9229.That is right when the page and the provider are on the same machine, and wrong the moment they are not. A phone or an iOS simulator loading the demo over the LAN resolves
localhostto itself, so the widget never reaches the provider. The failure surfaces as "Site key not registered", which reads like a configuration problem with the site key rather than what it is — the request went nowhere.It cost a while to work out when testing a mobile-only bug on a real device, because nothing in the error points at the provider URL.
What changed
PROSOPO_PROVIDER_URL_DEVELOPMENTnow overrides it:PROSOPO_PROVIDER_URL_DEVELOPMENT="https://192.0.2.10:9229" npm run start:bundleUnset, it still falls back to
https://localhost:9229, so existing setups are unaffected. Staging and production resolve through their DNS-routed endpoints and ignore it entirely.The URL was hardcoded in two places — the DNS endpoint map in
providers.tsand the single-provider dev list inbalancer.ts— and both now read the same resolver.Two details worth a look in review
process.env.Xaccess, because the frontend build substitutes that exact expression for a literal. A computed lookup (process.env[key]) would not be matched and would silently never work in the browser. For the same reason there is notypeof processguard: in a browser bundle the expression is already a string by the time it runs, and guarding on aprocessthat does not exist there would throw the value away.Effect
Development only. No change to staging or production behaviour, and no change when the variable is unset.
Test coverage
7 tests: the default, an override, trailing-slash normalisation, empty and whitespace-only values falling back rather than yielding an empty URL, reading the variable, and the unset case.
Also checked end to end against the built package — with the variable set,
getRandomActiveProvider("development")andloadBalancer("development")both return the override; without it, both returnhttps://localhost:9229.Suite: 49 passed, 0 type errors.
🤖 Generated with Claude Code