Allow local overrides of the dev server config - #201
Conversation
Testing the mediator from a phone means serving it under a tunnel hostname, which requires changing `server.host` and `server.baseUri` -- values in a tracked config that differ per machine. `configs/dev.js` now imports `configs/local.js` last, when present, so those overrides win. The file is gitignored; absent it, behavior is unchanged.
The override is only discoverable by reading `configs/dev.js`, and anyone using it has to derive the file's shape and the bedrock config keys involved from scratch. `configs/local.js.example` is a copyable starting point covering the case the override exists for: serving the mediator under a tunnel hostname so a phone can reach it. It carries the reasoning that is easy to get wrong -- why `server.host` and `server.baseUri` are set rather than `server.domain`, and why the tunnel must point at the HTTPS port rather than the HTTP one, which would redirect to itself forever. The hostname is a placeholder. Also corrects the Configuration section, which pointed at `./configs/authn.localhost.js`. That file is `authn.localhost.js` at the repository root; the tunable config is `configs/dev.js`.
|
Mechanism works — confirmed the load ordering (top-level
|
Import by file URL, not filesystem path. `import()` takes a URL, so a bare
absolute path truncates at a `#` in any parent directory name -- reporting a
module nobody asked for -- and on Windows parses the drive letter as a URL
scheme. Reproduced both with a `#` in the path; `pathToFileURL` fixes it.
Drop `server.baseUri` from the example. It is the lazily-evaluated template
`https://${server.host}`, so it already follows `host`; setting both ships two
values that must agree, which is the mismatch the surrounding prose warns
about. Verified by removing it: both the tunnel and local origins still serve.
Correct the `bindAddr` justification. `configs/dev.js` hard-assigns
`config.server.bindAddr`, so setting `server.domain` cannot affect it -- the
reason to prefer `server.host` is that `host` appends the port.
Point `configs/dev.js` at `server.host` rather than `server.domain`. That
comment is the first thing a reader opens and it recommended the knob the
example warns against.
Note that the file cannot register bedrock event handlers, since it is
imported after `@bedrock/config-yaml` and would trip that package's
last-import assertion with a message that does not explain itself.
Note that overriding `server.host` stops `@bedrock/express` sending
`Access-Control-Allow-Private-Network`, which it gates on `host` containing
`localhost`. Traffic through the tunnel is unaffected, but a public-origin
coordinator reaching the local mediator directly will start failing Chrome's
private-network preflight while the file is in place.
Name `local.js` as the development override channel, since
`@bedrock/config-yaml` is a third nominal channel with no stated precedence.
Show restricting `server.bindAddr` to loopback in the example. The all-
interfaces default exists for Docker and is documented as such, but nothing
offers the alternative at the point of use.
Correct the README's Node and npm versions, which read v16+/v8+ against an
`engines.node` of `>=24`.
|
Thanks — all of it applied in 0b7e2cd. Verified each point rather than taking it on trust; every one held. The
The
The three smaller points are all in, each as a sentence where it applies: no event handlers (with the reason, since that error message explains nothing), the On The asides. README Node/npm versions corrected to v24+/v10+ against
|
Testing the mediator from a phone means serving it under a tunnel hostname,
which requires changing
server.hostandserver.baseUri— values in atracked config that differ per machine. Editing
configs/dev.jsdirectlyrisks committing them or losing them in a rebase.
configs/dev.jsnow importsconfigs/local.jslast, when present, so thoseoverrides win. The file is gitignored. Absent it, behavior is unchanged.
Using it
Then replace the placeholder hostname and restart. Delete the file to go back
to the defaults.
configs/local.js.exampleis committed as a copyable starting point coveringthe case the override exists for. It carries the two things that are easy to
get wrong:
server.hostandserver.baseUri, notserver.domain.domainalso drives
server.bindAddr, andhostappendsserver.portunless theport is 443 — so overriding the port to 443 to get a clean hostname stops
the server listening on 33443 locally.
port redirects unconditionally to
https://<server.host>; with a tunnelhostname that redirects to itself forever.
Why not bedrock's
--configflag?bedrock.start()already imports every--configpath, after the staticconfig imports and before
bedrock.configure, sonode authn.localhost.js --config ./configs/local.jswould get the sameresult with no change to
configs/dev.js.Auto-loading is chosen because it applies without being remembered. Every
existing script, README line, and habit says plain
npm start; an overridethat needs a flag is one a developer will lose on the next terminal. Making
the file's presence the switch means the override survives contact with
muscle memory, and deleting the file is the way back.
@bedrock/config-yaml, imported fromlib/index.js, is a third nominalchannel. It reads
/etc/bedrock-config/app.yamlor a base64 blob inBEDROCK_CONFIG, which suits deployment rather than a working copy, soconfigs/dev.jsnow nameslocal.jsas the development channel to save thenext reader the comparison.
Also
Corrects the README's Configuration section, which pointed at
./configs/authn.localhost.js. That file isauthn.localhost.jsat therepository root; the tunable config is
configs/dev.js.Corrects the README's stated Node and npm versions, which read v16+ and v8+
against an
engines.nodeof>=24.Why
Split out from #200, which needed this to test on a real device, so it can be
reviewed on its own.