feat: 12-factor env vars FLAPI_PORT + FLAPI_HOST (#63)#67
Merged
Conversation
- main.cpp: FLAPI_PORT / FLAPI_HOST fallback for --port / --host with CLI > env > config > default precedence; invalid FLAPI_PORT (non-int / out of range) exits 1 with single-line stderr, mirroring the FLAPI_LOG_LEVEL pattern from #47 - main.cpp: new --host CLI flag, paired with FLAPI_HOST - config_manager: http-host YAML key (default 0.0.0.0) + get/setHttpHost accessors - api_server: pass bindaddr to crow so the configured host is honoured - test_env_overrides.py: 7 new pytest cases covering invalid FLAPI_PORT (abc / 0 / 99999 / -1), env-only port bind, CLI-wins-over-env precedence, and FLAPI_HOST bind - CLI_REFERENCE / CONFIG_REFERENCE / AGENTS: docs reflect the new env vars and the http-host config field
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
Wires
FLAPI_PORTandFLAPI_HOSTenv-var fallbacks for the HTTPserver, mirroring the
FLAPI_CONFIG/FLAPI_LOG_LEVELpattern from#47 / PR #57. Adds a paired
--hostCLI flag (there was no host flagbefore) and a matching
http-hostYAML config key.Precedence is the standard 12-factor flavour: CLI > env > config
file > built-in default. Invalid
FLAPI_PORT(non-integer,<1,>65535) exits 1 with a single-line stderr message so typos surfaceimmediately instead of silently falling through to the config-file
value.
Changes
src/main.cpp:--hostargparse flag;FLAPI_PORT/FLAPI_HOSTfallbacks with
is_used()precedence; range-checked port parsing.src/include/config_manager.hpp+src/config_manager.cpp:http-hostYAML key (default0.0.0.0) +getHttpHost/setHttpHost.src/api_server.cpp: passbindaddrto Crow so the configuredhost is honoured (was hard-coded to the Crow default).
test/integration/test_env_overrides.py: 7 new cases coveringinvalid
FLAPI_PORT(parametrised overabc/0/99999/-1),env-only port bind, CLI-wins-over-env precedence, and
FLAPI_HOSTbind. The bind tests open a real listening socket on a free port
rather than relying on
--validate-config.docs/CLI_REFERENCE.md: dedicated--hostsection,FLAPI_PORT/FLAPI_HOSTrows in the env-vars table, updated--portsectionwith the new precedence.
docs/CONFIG_REFERENCE.md:http-hostrow in the server configtable and the 12-factor checklist; default-values appendix updated.
AGENTS.md(=CLAUDE.mdsymlink): env-vars block updated.Test plan
make debugcleancmake --build build/release --config Releasecleanctest(637 / 637 pass serially; parallel run hits apre-existing DatabaseManager race unrelated to this change)
pytest test/integration/test_env_overrides.py -v— all 13 pass(6 pre-existing + 7 new)
FLAPI_PORT=19090 FLAPI_HOST=127.0.0.1 ./flapi -c …binds on
127.0.0.1:19090, confirmed viass -tlnpFLAPI_PORT={abc,0,99999}each exit 1 with thedocumented stderr line
Closes #63.