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 RedisManager (no-op if
REDIS_URLis empty) - 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 - Sets up Jinja2 templates — extensible
FileSystemLoaderwithtemplates/auto-detected - Mounts the health router —
/healthand/readiness - Mounts the welcome page (if
welcome=True) — interactive landing page at/ - Auto-discovers routers — scans
*/api.pyand mounts routers by convention - Mounts the demo app (if
demo=True) — Todo CRUD at/demo/todos
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
settings | BluefoxSettings | required | Application settings |
welcome | bool | False | Mount the welcome page at / |
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 | RedisManager | Redis manager (client may be None) |
app.state.templates | jinja2.Environment | Jinja2 environment with extensible loader |
Welcome page¶
The welcome page is served at GET / when welcome=True. It shows status badges for the app, database, and Redis, plus an interactive message playground.
Remove it by dropping the welcome=True parameter: