From cd46d581b5a30d9285b4e78a15c8c46916e832d1 Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 27 May 2025 01:03:21 +0200 Subject: [PATCH] fix: disable auth for data API endpoints and add CORS preflight handling --- nginx.conf | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/nginx.conf b/nginx.conf index 2a768a4..640a64a 100644 --- a/nginx.conf +++ b/nginx.conf @@ -44,8 +44,10 @@ server { add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization' always; } - # Proxy requests to the data API + # Proxy requests to the data API - no auth required for API endpoints location /data/ { + # No authentication for data API to allow the app to save/load data + auth_basic off; # Explicitly disable auth for data API proxy_pass http://localhost:3000/data/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; @@ -59,6 +61,17 @@ server { add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization' always; + + # Handle preflight requests for the API + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization'; + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain charset=UTF-8'; + add_header 'Content-Length' 0; + return 204; + } } # Enable browser caching for static assets