-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
35 lines (29 loc) · 1.22 KB
/
Copy pathmain.py
File metadata and controls
35 lines (29 loc) · 1.22 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
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from backend.routers import profile, simulation, feedback, knowledge
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse
app = FastAPI(title="Loopback API", description="Relationship Simulation System Backend")
# Configure CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:5173", "http://127.0.0.1:5173"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.exception_handler(RequestValidationError)
async def validation_exception_handler(request, exc):
print("VALIDATION ERROR DETAILS:", exc.errors())
return JSONResponse(
status_code=422,
content={"detail": exc.errors()},
)
# Include routers
app.include_router(profile.router, prefix="/api/profile", tags=["profile"])
app.include_router(simulation.router, prefix="/api/simulation", tags=["simulation"])
app.include_router(feedback.router, prefix="/api/feedback", tags=["feedback"])
app.include_router(knowledge.router, prefix="/api/knowledge", tags=["knowledge"])
@app.get("/")
async def root():
return {"message": "Welcome to the Loopback Relationship Simulation API"}