-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (54 loc) · 1.6 KB
/
main.py
File metadata and controls
67 lines (54 loc) · 1.6 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from config.database_config import Base, engine
from routes.agent_routes import router as agent_router
from routes.user_routes import router as auth_router
@asynccontextmanager
async def lifespan(app: FastAPI):
# Startup: Create database tables
Base.metadata.create_all(bind=engine)
yield
# Shutdown: Cleanup if needed (Vercel allows max 500ms for cleanup)
pass
app = FastAPI(
title="CortexAI API",
lifespan=lifespan
)
cors_origins = os.getenv("BACKEND_CORS_ORIGINS", "http://localhost:5173")
origins = [o.strip() for o in cors_origins.split(",") if o.strip()]
# If no origins specified, allow common localhost variants for development
if not origins:
origins = [
"http://localhost:5173",
"http://127.0.0.1:5173",
"http://localhost:3000",
"http://127.0.0.1:3000",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"],
allow_headers=["*"],
expose_headers=["*"],
)
app.include_router(auth_router)
app.include_router(agent_router)
# standerd response for the root path
@app.get("/")
async def root():
return {
"message": "Welcome to the CortexAI API",
"version": "1.0.0",
"status": "success"
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"main:app",
host="0.0.0.0",
port=int(os.getenv("PORT", "8000")),
reload=True,
)