template tutoring-admin-dashboard v1
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""FastAPI entry point. Deploy imports ``app.main:app`` — keep both names."""
|
||||
|
||||
import os
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.routes import api_router
|
||||
from app.seed import init_db
|
||||
|
||||
app = FastAPI(title=os.getenv("APP_NAME", "SwatiYadav"))
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
def _startup() -> None:
|
||||
try:
|
||||
init_db()
|
||||
except Exception as exc: # noqa: BLE001
|
||||
print(f"[startup] DB init skipped: {exc}")
|
||||
|
||||
# Allowed origins come from the environment so the deployed app and local dev
|
||||
# use the same code path. "*" only when nothing is configured (dev default).
|
||||
_origins = [o.strip() for o in os.getenv("CORS_ORIGINS", "*").split(",") if o.strip()]
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=_origins,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# The one place the /api prefix is applied. Route modules must not repeat it.
|
||||
app.include_router(api_router, prefix="/api")
|
||||
Reference in New Issue
Block a user