-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
46 lines (41 loc) · 1.33 KB
/
Copy pathmain.py
File metadata and controls
46 lines (41 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import uvicorn
import asyncio
from fastapi import FastAPI
from contextlib import asynccontextmanager
from fastapi.middleware.cors import CORSMiddleware
from api.routes import router
from api.health import router as health_router, background_health_check
from database.connection import init_db
from core.config import settings
@asynccontextmanager
async def lifespan(app: FastAPI):
# Startup behavior
print("Starting up: Initializing database...")
await init_db()
print("Starting background health check task...")
asyncio.create_task(background_health_check())
yield
# Shutdown behavior
print("Shutting down gracefully...")
app = FastAPI(
title=settings.PROJECT_NAME,
description="Scientific Research Agent Platform REST API",
version="0.1.0",
docs_url="/api/docs",
openapi_url="/api/openapi.json",
redoc_url="/api/redoc",
lifespan=lifespan
)
# Add CORS Middleware to allow Next.js frontend to call the API
app.add_middleware(
CORSMiddleware,
allow_origins=[settings.FRONTEND_URL, "http://localhost:3000"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Register routes
app.include_router(router, prefix="/api")
app.include_router(health_router, prefix="/api")
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)