-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (50 loc) · 1.82 KB
/
main.py
File metadata and controls
60 lines (50 loc) · 1.82 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
import os
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from routes import query, azure, system, user_queries, data_documents
app = FastAPI()
# Configure CORS origins based on environment
# Check for production indicators
is_production = (
os.getenv("ENVIRONMENT") == "production"
or os.getenv("K_SERVICE") is not None # Google Cloud Run
)
if is_production:
# Production: Only allow specific origins
allowed_origins = [
"https://querypal.virtonomy.io", # Production frontend
"https://querypal-frontend-zynyyoxona-ew.a.run.app", # Cloud Run frontend URL (pattern)
# Add your actual Cloud Run frontend URL when you know it
]
else:
# Development: Allow localhost origins
allowed_origins = [
"http://localhost:8000",
"http://localhost:5173",
"http://127.0.0.1:8000",
"http://127.0.0.1:5173",
]
print(f"🔧 CORS Configuration - Production mode: {is_production}")
print(f"🌐 Allowed origins: {allowed_origins}")
app.add_middleware(
CORSMiddleware,
allow_origins=allowed_origins,
allow_credentials=True,
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"],
allow_headers=["*"],
)
@app.get("/health")
async def health_check():
"""Health check endpoint."""
return {
"status": "healthy",
"cors_production_mode": is_production,
}
app.include_router(query.router, prefix="/query", tags=["Query"])
app.include_router(azure.router, prefix="/azure", tags=["Azure"])
app.include_router(system.router, prefix="/system", tags=["System"])
app.include_router(user_queries.router, prefix="/user", tags=["User Queries"])
app.include_router(data_documents.router, prefix="/data", tags=["Data Documents"])
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)