Skip to content

feat(fastapi): add APP_URL support to FastAPIConfig#111

Open
bedus-creation wants to merge 4 commits into
mainfrom
fix/fastapi-config-app-url
Open

feat(fastapi): add APP_URL support to FastAPIConfig#111
bedus-creation wants to merge 4 commits into
mainfrom
fix/fastapi-config-app-url

Conversation

@bedus-creation

Copy link
Copy Markdown
Contributor

Summary

  • Adds APP_URL env var support to FastAPIConfig so host and port can be derived from a full URL (e.g. http://myapp.com:8080 or https://production.example.com)
  • Introduces _parse_app_url(), _default_host(), and _default_port() helper functions with clear priority rules
  • Resolution order: APP_HOST/APP_PORT wins → APP_URL hostname/port → hard-coded defaults (127.0.0.1 / 8000)
  • URLs without a scheme (e.g. myapp.com:9000) are handled by prepending http:// before parsing

Changes

  • fastapi_startkit/src/fastapi_startkit/fastapi/config/fastapi.py — rewired host/port fields to use new helper functions; added urllib.parse and os imports
  • fastapi_startkit/tests/fastapi/test_fastapi_config.py — 15 new tests across 4 test classes covering all resolution scenarios

Test plan

  • No env vars → host="127.0.0.1", port=8000
  • APP_HOST + APP_PORT set → those values used
  • APP_URL=http://myapp.com:9000host="myapp.com", port=9000
  • APP_URL=https://production.example.comhost="production.example.com", port=8000 (no port in URL)
  • APP_URL=http://myapp.com:9000 + APP_HOST=override.comAPP_HOST wins: "override.com"
  • APP_URL=myapp.com:9000 (no scheme) → host="myapp.com", port=9000
  • All 15 tests pass: uv run pytest tests/fastapi/test_fastapi_config.py -v

🤖 Generated with Claude Code

bedus-creation and others added 4 commits June 10, 2026 17:02
…ivation

Parse APP_URL (e.g. http://myapp.com:8080 or https://production.example.com)
to derive default host and port. Priority order: APP_HOST/APP_PORT env vars
win, then APP_URL hostname/port, then hard-coded defaults (127.0.0.1/8000).
Adds 15 tests covering all resolution scenarios.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace three-function APP_URL parsing helpers with a single
_parse_app_url(component) helper and inline or-chain lambdas in the
dataclass fields. Remove all importlib.reload() calls from the test
suite — monkeypatch works directly since default_factory lambdas
call env() at instantiation time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…o ServeCommand

FastAPIConfig now stores only raw env values (APP_HOST, APP_PORT, APP_URL)
with no parsing logic or hardcoded defaults.  _resolve_host_port() in
ServeCommand owns the full APP_HOST/APP_PORT → APP_URL → 127.0.0.1/8000
resolution chain, making the priority order explicit and testable in
isolation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant