App factory¶
create_bluefox_app() builds a fully configured FastAPI application.
Usage¶
from bluefox_core import BluefoxSettings, create_bluefox_app
settings = BluefoxSettings()
app = create_bluefox_app(settings)
What it does¶
- Configures logging via
configure_logging(settings) - Creates a DatabaseManager (no-op if
DATABASE_URLis empty) - Creates a Redis client (if
REDIS_URLis set) - Sets up the lifespan — startup verifies DB/Redis connectivity, shutdown disposes resources (wrapped in
try/finallyfor safe cleanup) - Adds middleware:
RequestIDMiddleware— injectsX-Request-IDheaders and log contextCORSMiddleware— permissive in development, restrictive in production
- Stores state —
app.state.db,app.state.redis,app.state.settings - Mounts the health router —
/healthand/readiness - Mounts the demo app (if
demo=True) — Todo CRUD at/demo/todos - Mounts the welcome page — shown at
/when no user route exists for that path
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
settings | BluefoxSettings | required | Application settings |
demo | bool | False | Mount the demo Todo CRUD app |
CORS behavior¶
| Setting | Development | Production |
|---|---|---|
allow_origins | ["*"] | [] |
allow_credentials | True | False |
allow_methods | ["*"] | ["GET", "POST", "PUT", "PATCH", "DELETE"] |
allow_headers | ["*"] | ["*"] |
App state¶
After creation, the following are available on app.state:
| Attribute | Type | Description |
|---|---|---|
app.state.settings | BluefoxSettings | The settings instance |
app.state.db | DatabaseManager | Database manager (engine may be None) |
app.state.redis | Redis | None | Redis client, or None if not configured |
Welcome page¶
The welcome page is served at GET / via a 404 exception handler. When you register your own GET / route, FastAPI matches it first and the welcome page is never triggered.