51 lines
2.2 KiB
Text
51 lines
2.2 KiB
Text
server {
|
|
listen 8334;
|
|
server_name localhost;
|
|
|
|
# Map to dynamically set CORS origin based on request
|
|
# This allows multiple localhost ports for development
|
|
set $cors_origin "";
|
|
if ($http_origin ~* "^http://localhost:(5173|5174|5175|3000|8080)$") {
|
|
set $cors_origin $http_origin;
|
|
}
|
|
|
|
# Proxy to SeaweedFS S3 endpoint
|
|
location / {
|
|
# Hide CORS headers from upstream SeaweedFS (to prevent duplicates)
|
|
proxy_hide_header 'Access-Control-Allow-Origin';
|
|
proxy_hide_header 'Access-Control-Allow-Methods';
|
|
proxy_hide_header 'Access-Control-Allow-Headers';
|
|
proxy_hide_header 'Access-Control-Expose-Headers';
|
|
proxy_hide_header 'Access-Control-Max-Age';
|
|
proxy_hide_header 'Access-Control-Allow-Credentials';
|
|
|
|
# CORS Headers for development - dynamically set based on request origin
|
|
add_header 'Access-Control-Allow-Origin' $cors_origin always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, PUT, POST, DELETE, HEAD, OPTIONS' always;
|
|
add_header 'Access-Control-Allow-Headers' '*' always;
|
|
add_header 'Access-Control-Expose-Headers' 'ETag, Content-Length, Content-Type' always;
|
|
add_header 'Access-Control-Max-Age' '3600' always;
|
|
|
|
# Handle preflight requests
|
|
if ($request_method = 'OPTIONS') {
|
|
add_header 'Access-Control-Allow-Origin' $cors_origin always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, PUT, POST, DELETE, HEAD, OPTIONS' always;
|
|
add_header 'Access-Control-Allow-Headers' '*' always;
|
|
add_header 'Access-Control-Max-Age' '3600' always;
|
|
add_header 'Content-Type' 'text/plain; charset=utf-8' always;
|
|
add_header 'Content-Length' '0' always;
|
|
return 204;
|
|
}
|
|
|
|
# Proxy to SeaweedFS
|
|
proxy_pass http://seaweedfs:8333;
|
|
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;
|
|
|
|
# Important for large file uploads
|
|
proxy_request_buffering off;
|
|
client_max_body_size 1G;
|
|
}
|
|
}
|