first commit
This commit is contained in:
45
backend/app/main.py
Normal file
45
backend/app/main.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import Response
|
||||
|
||||
from app.core.config import settings
|
||||
from app.core.logging import setup_logging
|
||||
from app.core.db import init_db, get_session
|
||||
from app.core.security import bootstrap_admin_if_needed
|
||||
from app.api.routes_auth import router as auth_router
|
||||
from app.api.routes_routers import router as routers_router
|
||||
from app.api.routes_dashboards import router as dashboards_router
|
||||
from app.api.routes_stream import router as stream_router
|
||||
|
||||
setup_logging()
|
||||
|
||||
app = FastAPI(title=settings.APP_NAME)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=[o.strip() for o in settings.CORS_ORIGINS.split(",") if o.strip()],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
@app.on_event("startup")
|
||||
async def on_startup():
|
||||
await init_db()
|
||||
async for session in get_session():
|
||||
await bootstrap_admin_if_needed(session)
|
||||
break
|
||||
|
||||
@app.get("/healthz")
|
||||
async def healthz():
|
||||
return {"ok": True}
|
||||
|
||||
# 204 na favicon (ucisza spam)
|
||||
@app.get("/favicon.ico")
|
||||
async def favicon():
|
||||
return Response(status_code=204)
|
||||
|
||||
app.include_router(auth_router, prefix="/auth", tags=["auth"])
|
||||
app.include_router(routers_router, prefix="/api/routers", tags=["routers"])
|
||||
app.include_router(dashboards_router, prefix="/api/dashboards", tags=["dashboards"])
|
||||
app.include_router(stream_router, tags=["stream"])
|
||||
Reference in New Issue
Block a user