Spaces:
Running
Running
Update origin to have the correct frontend url
Browse files- app/main.py +34 -32
app/main.py
CHANGED
@@ -1,33 +1,35 @@
|
|
1 |
-
from fastapi import FastAPI, Response
|
2 |
-
from app.api.v1.api import api_router
|
3 |
-
from fastapi.middleware.cors import CORSMiddleware
|
4 |
-
|
5 |
-
from app.models.schemas import StandardResponse
|
6 |
-
|
7 |
-
app = FastAPI(title="Cognisafe API")
|
8 |
-
|
9 |
-
origins = [
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
"""
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
33 |
app.include_router(api_router, prefix="/api/v1")
|
|
|
1 |
+
from fastapi import FastAPI, Response
|
2 |
+
from app.api.v1.api import api_router
|
3 |
+
from fastapi.middleware.cors import CORSMiddleware
|
4 |
+
|
5 |
+
from app.models.schemas import StandardResponse
|
6 |
+
|
7 |
+
app = FastAPI(title="Cognisafe API")
|
8 |
+
|
9 |
+
origins = [
|
10 |
+
"https://cognisafe.netlify.app"
|
11 |
+
]
|
12 |
+
|
13 |
+
app.add_middleware(
|
14 |
+
CORSMiddleware,
|
15 |
+
allow_origins=origins, # or ["*"] for all origins (not recommended in prod)
|
16 |
+
allow_credentials=True,
|
17 |
+
allow_methods=["*"],
|
18 |
+
allow_headers=["*"],
|
19 |
+
)
|
20 |
+
|
21 |
+
@app.get("/health")
|
22 |
+
async def health_check():
|
23 |
+
return {"status": "healthy"}
|
24 |
+
|
25 |
+
@app.get("/helloworld", response_model=StandardResponse)
|
26 |
+
def helloworld(response: Response) -> StandardResponse:
|
27 |
+
"""
|
28 |
+
Returns helloworld as the standard response
|
29 |
+
"""
|
30 |
+
response.status_code = 200
|
31 |
+
response = StandardResponse(error=False, title="Hello World", status=200)
|
32 |
+
return response
|
33 |
+
|
34 |
+
|
35 |
app.include_router(api_router, prefix="/api/v1")
|