Skip to content

Commit 2cd784a

Browse files
committed
added a route to handle OPTIONS requests specificallys to debug the CORS rejection from safary
1 parent 1bf5eff commit 2cd784a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

server/main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
async def referer_and_path_middleware(request: Request, call_next):
3232
# Check the Referer header
3333
referer = request.headers.get("referer")
34-
allowed_referer = "https://ricardogarcia.uk"
34+
allowed_referers = ["https://ricardogarcia.uk", "https://rigsnv-ejfqade8hydkh3c8.uksouth-01.azurewebsites.net/"]
3535

3636
# Check the request path
3737
allowed_paths = ["/weather", "/pcs_contracts"]
3838

39-
if referer and referer.startswith(allowed_referer) and request.url.path in allowed_paths:
39+
if referer and any(referer.startswith(allowed) for allowed in allowed_referers) and request.url.path in allowed_paths:
4040
response = await call_next(request)
4141
return response
4242

@@ -78,4 +78,12 @@ def update_contracts(date_from=None, notice_type=3, output_type=0):
7878
client = PCSClient()
7979
return client.get_pcs_contracts(date_from=date_from, notice_type=notice_type, output_type=output_type)
8080

81+
@app.options("/{path:path}")
82+
async def preflight_handler():
83+
return JSONResponse(status_code=200, headers={
84+
"Access-Control-Allow-Origin": "https://ricardogarcia.uk",
85+
"Access-Control-Allow-Methods": "GET, POST, PUT, OPTIONS",
86+
"Access-Control-Allow-Headers": "Content-Type, Authorization",
87+
})
88+
8189
#test, this should trigger a build

0 commit comments

Comments
 (0)