File size: 1,172 Bytes
52afd45
 
 
 
 
 
 
 
 
6e366d5
 
 
 
 
52afd45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d68e65a
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
from fastapi import FastAPI, Response
from app.api.v1.api import api_router
from fastapi.middleware.cors import CORSMiddleware

from app.models.schemas import StandardResponse

app = FastAPI(title="Cognisafe API")

origins = [
    "https://cognisafe.netlify.app",  # Your frontend origin
    "https://zyriean-cognisafe-backend.hf.space", # <-- **THIS IS CRUCIAL**
    # You might also want to include localhost for local development:
    "http://localhost",
    "http://localhost:8000", # Or whatever port you use for local testing
]
app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,  # or ["*"] for all origins (not recommended in prod)
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

@app.get("/health")
async def health_check():
    return {"status": "healthy"}

@app.get("/helloworld", response_model=StandardResponse)
def helloworld(response: Response) -> StandardResponse:
    """
    Returns helloworld as the standard response
    """
    response.status_code = 200
    response = StandardResponse(error=False, title="Hello World", status=200)
    return response


app.include_router(api_router, prefix="/api/v1")