diff --git a/nginx.conf b/nginx.conf index 690108e..d15f0ba 100644 --- a/nginx.conf +++ b/nginx.conf @@ -85,6 +85,39 @@ http { proxy_set_header Upgrade websocket; } + # ====================== /server/ location ====================== + location ~ "^/server/" { + # Preflight OPTIONS - handled by nginx (fast, no hit to Flask) + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' $allow_origin always; + add_header 'Access-Control-Allow-Credentials' 'true' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, PATCH, OPTIONS' always; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,X-CSRF-Token' always; + add_header 'Access-Control-Max-Age' 1728000 always; # 20 days + add_header 'Content-Type' 'text/plain; charset=utf-8'; + add_header 'Content-Length' 0; + return 204; + } + + # Normal requests + limit_except DELETE GET POST PUT OPTIONS { deny all; } + + add_header 'Access-Control-Allow-Origin' $allow_origin always; + add_header 'Access-Control-Allow-Credentials' 'true' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, PATCH, OPTIONS' always; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,X-CSRF-Token' always; + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; + add_header 'Vary' 'Origin' always; + + rewrite "^/server/(.*)" /$1 break; + proxy_pass http://localhost:3000; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + # Catch-all for anything else (optional, returns proper CORS even on 404) location / { if ($request_method = 'OPTIONS') {