feat: backend FastAPI Smart App City — auth JWT, IoT, GIS, notifications, reporting
This commit is contained in:
50
smart-app-city/backend/app/main.py
Normal file
50
smart-app-city/backend/app/main.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""
|
||||
Smart App City — Main Application
|
||||
FastAPI backend avec JWT, IoT, GIS, Notifications, Reporting
|
||||
"""
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.config import settings
|
||||
from app.database import init_db, close_db
|
||||
from app.routes.auth import router as auth_router
|
||||
from app.routes.iot import router as iot_router
|
||||
from app.routes.gis import router as gis_router
|
||||
from app.routes.notifications import router as notifications_router
|
||||
from app.routes.reporting import router as reporting_router
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""Startup and shutdown events."""
|
||||
await init_db()
|
||||
yield
|
||||
await close_db()
|
||||
|
||||
app = FastAPI(
|
||||
title="Smart App City",
|
||||
description="Backend API pour l'application mobile Smart City Digital Twin Martinique",
|
||||
version="0.1.0",
|
||||
lifespan=lifespan,
|
||||
)
|
||||
|
||||
# CORS
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=settings.CORS_ORIGINS,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# Routes
|
||||
app.include_router(auth_router, prefix="/api/v1")
|
||||
app.include_router(iot_router, prefix="/api/v1")
|
||||
app.include_router(gis_router, prefix="/api/v1")
|
||||
app.include_router(notifications_router, prefix="/api/v1")
|
||||
app.include_router(reporting_router, prefix="/api/v1")
|
||||
|
||||
@app.get("/health", tags=["health"])
|
||||
async def health_check():
|
||||
"""Health check endpoint."""
|
||||
return {"status": "healthy", "version": "0.1.0"}
|
||||
Reference in New Issue
Block a user