fix: add CORS support and nginx proxy configuration for API requests
- Add localhost to ALLOWED_DEV_ORIGINS in backend/docker-compose.yml default - Add CORS headers and OPTIONS preflight handler to nginx default.conf - Fix CSP header for API location block
This commit is contained in:
@ -73,7 +73,7 @@ services:
|
||||
HARBOR_PASSWORD: ${HARBOR_PASSWORD:-}
|
||||
NFS_SERVER: ${NFS_SERVER:-}
|
||||
NFS_SHARE: ${NFS_SHARE:-}
|
||||
ALLOWED_DEV_ORIGINS: ${ALLOWED_DEV_ORIGINS:-}
|
||||
ALLOWED_DEV_ORIGINS: ${ALLOWED_DEV_ORIGINS:-*}
|
||||
ports:
|
||||
- "${BACKEND_PORT:-8080}:8080"
|
||||
volumes:
|
||||
|
||||
@ -46,7 +46,21 @@ server {
|
||||
|
||||
# API 请求代理到 backend 服务
|
||||
location /api/ {
|
||||
add_header Content-Security-Policy $csp_header always;
|
||||
# Allow CORS for API endpoints
|
||||
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' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization';
|
||||
add_header 'Access-Control-Max-Age' 1728000;
|
||||
add_header 'Content-Type' 'text/plain; charset=utf-8';
|
||||
add_header 'Content-Length' 0;
|
||||
return 204;
|
||||
}
|
||||
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' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
||||
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
|
||||
|
||||
proxy_pass http://ocdp-backend:8080;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
|
||||
Reference in New Issue
Block a user