Read CLI and server options from env vars and a config file - #56
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Read CLI and server options from env vars and a config file#56devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Refs #12 Adds src/config.js with the configuration layers used by the CLI and osmsm serve: OSMSM_* env vars and a JSON config file (--config / OSMSM_CONFIG, ./osmsm.config.json, ~/.config/osmsm/config.json). Precedence is CLI flags > env vars > config file > built-in defaults. The library API is unaffected. The server app is now built by createApp(settings) so the CLI can pass the resolved headerCheck/port and render defaults explicitly; the legacy PORT/HEADER_CHECK/HEADER_CHECK_FAIL_MESSAGE env vars keep working. Co-Authored-By: Julian Perelli <jperelli@gmail.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
Refs #12
The CLI and
osmsm servecan now take defaults fromOSMSM_*env vars and from a JSON config file, with the precedence CLI flags > env vars > config file > built-in defaults. The library (src/lib.js) is untouched: it keeps using exactly the options passed to it.New module
src/config.js(added to the publishedfiles):src/cli.jsuses commander'sgetOptionValueSource(key) === "cli"to separate explicitly passed flags from built-in defaults, so env/config values sit between them. It adds-C, --config <path>(global, also works asosmsm serve --config x), warns on stderr about unknown config keys, and exits with code 2 on a missing explicit config file or an uncoercible value.osmsm servegains--headerCheck <name:value>and--headerCheckFailMessage <string>(previously env-only),--portdefaults to 3000 through the same resolution, and any render option coming from env/config is used as the default for every request (request params still win). To make this explicit and testable,src/server.jsnow exports:and the handler renders
osmsm({ ...defaults, ...params }).Docs: new "Configuration (CLI and server)" section in README (precedence, env var naming, file lookup order, server options table), CHANGELOG entry under "Unreleased".
Tests (
npm test, 47 passing, no browser needed for the new ones):test/config.test.js(unit),test/cli.test.js(spawns the CLI with-Din a temp cwd / isolated env to check each layer and the precedence),test/server.test.js(createAppdefaults, header check, request override).Notes / decisions for the reviewer:
OSMSM_+ upper snake case of the long option (OSMSM_MAX_ZOOM,OSMSM_GEOJSONFILE). LegacyPORT/HEADER_CHECK/HEADER_CHECK_FAIL_MESSAGEkeep working, below theOSMSM_ones.port,headerCheck,headerCheckFailMessage) share the same object.process.exit(0)right afterprocess.stdout.write(v), which truncates output at 64KB when stdout is a pipe (e.g.osmsm -D | grep). The CLI tests capture stdout through a file to avoid it; worth a separate fix (process.stdout.write(v, () => process.exit(0))).Link to Devin session: https://app.devin.ai/sessions/d17c0e03ecff4994bf8d3f555c0547ba
Open in Devin Desktop: https://app.devin.ai/desktop/session/d17c0e03ecff4994bf8d3f555c0547ba?variant=devin
Requested by: @jperelli