Commit ·
d7ff81e
1
Parent(s): 8d29e78
fixed main
Browse files1234567896 unmodified lines161718192021222324252623 unmodified lines505152535455import uvicornfrom fastapi import FastAPI, APIRouterfrom fastapi.middleware.cors import CORSMiddlewarefrom fastapi.staticfiles import StaticFilesimport asynciofrom concurrent.futures import ThreadPoolExecutorfrom app.core.config import settingsfrom app.api.routes.videos import router as videos_router6 unmodified lines# Create database tablescreate_tables()# Create FastAPI appapp = FastAPI(title=settings.PROJECT_NAME,description=settings.PROJECT_DESCRIPTION,version=settings.VERSION,)# Configure CORS23 unmodified lines# Include API router in appapp.include_router(api_router, prefix=settings.API_V1_STR)@app.on_event("shutdown")async def shutdown_event():loop = asyncio.get_running_loop()1234567891011126 unmodified lines19202122232425262728293031323323 unmodified lines5758596061626364656667686970717273747576777879808182import uvicornfrom fastapi import FastAPI, APIRouter, Requestfrom fastapi.middleware.cors import CORSMiddlewarefrom fastapi.staticfiles import StaticFilesimport asynciofrom concurrent.futures import ThreadPoolExecutorfrom fastapi.responses import JSONResponseimport loggingimport timefrom app.core.config import settingsfrom app.api.routes.videos import router as videos_router6 unmodified lines# Create database tablescreate_tables()# Configure logginglogging.basicConfig(level=logging.INFO)logger = logging.getLogger(__name__)# Create FastAPI appapp = FastAPI(title="Behavior Analytics API",description="API for behavior analytics processing",version="1.0.0")# Configure CORS23 unmodified lines# Include API router in appapp.include_router(api_router, prefix=settings.API_V1_STR)@app.middleware("http")async def log_requests(request: Request, call_next):"""Log all requests and their processing time"""start_time = time.time()response = await call_next(request)process_time = time.time() - start_timelogger.info(f"Path: {request.url.path} Method: {request.method} Time: {process_time:.2f}s Status: {response.status_code}")return response@app.get("/")async def root():"""Root endpoint that returns API status"""return JSONResponse({"status": "ok","message": "Behavior Analytics API is running","version": "1.0.0","docs_url": "/docs", # Link to API documentation"openapi_url": "/openapi.json" # Link to OpenAPI schema})@app.on_event("shutdown")async def shutdown_event():loop = asyncio.get_running_loop()
behavior_backend/main.py+31-4