Fix CORS configuration for frontend access
- Set allow_credentials=False when using wildcard origins - Added explicit OPTIONS handler for preflight requests - Simplified CORS configuration to be more permissive - This should resolve CORS blocking from frontend applications
This commit is contained in:
parent
1501f02451
commit
2a70291924
11
main.py
11
main.py
@ -37,9 +37,10 @@ app = FastAPI(
|
|||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=["*"],
|
allow_origins=["*"],
|
||||||
allow_credentials=True,
|
allow_credentials=False, # Must be False when using wildcard origins
|
||||||
allow_methods=["*"],
|
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
|
expose_headers=["*"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Include routers
|
# Include routers
|
||||||
@ -62,6 +63,12 @@ async def health_check():
|
|||||||
return {"status": "healthy", "service": "uptime-monitoring-api"}
|
return {"status": "healthy", "service": "uptime-monitoring-api"}
|
||||||
|
|
||||||
|
|
||||||
|
@app.options("/{path:path}")
|
||||||
|
async def options_handler():
|
||||||
|
"""Handle preflight OPTIONS requests"""
|
||||||
|
return {"message": "OK"}
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user