feat(config): make CORS allowed origins configurable via env#697
feat(config): make CORS allowed origins configurable via env#697raulanatol wants to merge 2 commits into
Conversation
Replaces the hardcoded `origins` list in `src/main.py` with a new `CORSSettings` block (env prefix `CORS_`), exposed as `settings.CORS.ORIGINS`. Defaults match the prior hardcoded values, so self-hosted deployments behind custom domains can now whitelist their frontend without editing source. Documented in `.env.template` under a new CORS Settings section.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis PR externalizes CORS allowed origins from hardcoded values into a configurable ChangesCORS Configuration Externalization
Sequence DiagramsequenceDiagram
participant App as Application
participant Settings as AppSettings.CORS
participant Middleware as CORSMiddleware
App->>Settings: read ORIGINS (settings.CORS.ORIGINS)
App->>Middleware: add_middleware(..., allow_origins=settings.CORS.ORIGINS)
Middleware->>Middleware: enforce CORS using allow_origins
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
CORSSettingsblock (env prefixCORS_) and exposes it assettings.CORS.ORIGINS.src/main.pynow feedsallow_originsfromsettings.CORS.ORIGINSinstead of a hardcoded list. Defaults preserve the prior values (http://localhost,http://127.0.0.1:8000,https://api.honcho.dev) so existing deployments behave identically..env.template.Motivation: self-hosted deployments behind custom domains currently have to patch
src/main.pyto whitelist their frontend. With this change a single env var is enough:Scope is intentionally limited to
origins. Theallow_methods/allow_headerswildcards flagged in #394 are left as-is to keep this PR focused on the env-configurability hole; happy to follow up in a separate PR if maintainers want them tightened too.Test plan
uv run ruff check src/uv run ruff format --check src/uv run basedpyright src/main.py src/config.py— 0 errorsuv run python -c "from src.config import settings; print(settings.CORS.ORIGINS)"CORS_ORIGINS='["http://foo.test","https://bar.test"]' uv run python -c ...CORS_ORIGINSis setSummary by CodeRabbit
New Features
Chores