Skip to content

feat: 12-factor env vars FLAPI_PORT + FLAPI_HOST (#63)#67

Merged
jrosskopf merged 1 commit into
mainfrom
feature/gh-63-flapi-port-host
May 25, 2026
Merged

feat: 12-factor env vars FLAPI_PORT + FLAPI_HOST (#63)#67
jrosskopf merged 1 commit into
mainfrom
feature/gh-63-flapi-port-host

Conversation

@jrosskopf
Copy link
Copy Markdown
Contributor

Summary

Wires FLAPI_PORT and FLAPI_HOST env-var fallbacks for the HTTP
server, mirroring the FLAPI_CONFIG / FLAPI_LOG_LEVEL pattern from
#47 / PR #57. Adds a paired --host CLI flag (there was no host flag
before) and a matching http-host YAML 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 surface
immediately instead of silently falling through to the config-file
value.

Changes

  • src/main.cpp: --host argparse flag; FLAPI_PORT / FLAPI_HOST
    fallbacks with is_used() precedence; range-checked port parsing.
  • src/include/config_manager.hpp + src/config_manager.cpp:
    http-host YAML key (default 0.0.0.0) + getHttpHost / setHttpHost.
  • src/api_server.cpp: pass bindaddr to Crow so the configured
    host is honoured (was hard-coded to the Crow default).
  • test/integration/test_env_overrides.py: 7 new cases covering
    invalid FLAPI_PORT (parametrised over abc / 0 / 99999 / -1),
    env-only port bind, CLI-wins-over-env precedence, and FLAPI_HOST
    bind. The bind tests open a real listening socket on a free port
    rather than relying on --validate-config.
  • docs/CLI_REFERENCE.md: dedicated --host section, FLAPI_PORT /
    FLAPI_HOST rows in the env-vars table, updated --port section
    with the new precedence.
  • docs/CONFIG_REFERENCE.md: http-host row in the server config
    table and the 12-factor checklist; default-values appendix updated.
  • AGENTS.md (= CLAUDE.md symlink): env-vars block updated.

Test plan

  • make debug clean
  • cmake --build build/release --config Release clean
  • ctest (637 / 637 pass serially; parallel run hits a
    pre-existing DatabaseManager race unrelated to this change)
  • pytest test/integration/test_env_overrides.py -v — all 13 pass
    (6 pre-existing + 7 new)
  • Manual smoke: FLAPI_PORT=19090 FLAPI_HOST=127.0.0.1 ./flapi -c …
    binds on 127.0.0.1:19090, confirmed via ss -tlnp
  • Manual smoke: FLAPI_PORT={abc,0,99999} each exit 1 with the
    documented stderr line

Closes #63.

- 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
@jrosskopf jrosskopf merged commit 095d1fa into main May 25, 2026
21 checks passed
@jrosskopf jrosskopf deleted the feature/gh-63-flapi-port-host branch May 25, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

12-factor: FLAPI_PORT + FLAPI_HOST env vars

1 participant