From 6e5545b190fed697d38596487f0443b39ca3f3ce Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 29 May 2025 18:26:10 +0300 Subject: [PATCH] nonginx-cors --- main.py | 1 + nginx.conf.sigil | 34 +--------------------------------- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/main.py b/main.py index ae799469..70509504 100644 --- a/main.py +++ b/main.py @@ -47,6 +47,7 @@ middleware = [ allow_origins=[ "https://localhost:3000", "https://testing.discours.io", + "https://testing3.discours.io", "https://discours.io", "https://new.discours.io", "https://discours.ru", diff --git a/nginx.conf.sigil b/nginx.conf.sigil index 71d80d47..9b414bb7 100644 --- a/nginx.conf.sigil +++ b/nginx.conf.sigil @@ -1,5 +1,5 @@ log_format custom '$remote_addr - $remote_user [$time_local] "$request" ' - 'origin=$http_origin allow_origin=$allow_origin status=$status ' + 'origin=$http_origin status=$status ' '"$http_referer" "$http_user_agent"'; {{ $proxy_settings := "proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; proxy_set_header Host $http_host; proxy_set_header X-Request-Start $msec;" }} @@ -10,14 +10,6 @@ proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=1g limit_conn_zone $binary_remote_addr zone=addr:10m; limit_req_zone $binary_remote_addr zone=req_zone:10m rate=20r/s; -# Map to set CORS origin header -map $http_origin $allow_origin { - default ''; - "https://localhost:3000" "https://localhost:3000"; - "https://testing.discours.io" "https://testing.discours.io"; - "https://testing3.discours.io" "https://testing3.discours.io"; -} - {{ range $port_map := .PROXY_PORT_MAP | split " " }} {{ $port_map_list := $port_map | split ":" }} {{ $scheme := index $port_map_list 0 }} @@ -57,24 +49,6 @@ server { {{ $proxy_settings }} {{ $gzip_settings }} - # Add CORS headers for non-OPTIONS requests - add_header 'Access-Control-Allow-Origin' $allow_origin; - add_header 'Access-Control-Allow-Methods' 'POST, GET, OPTIONS'; - add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization'; - add_header 'Access-Control-Allow-Credentials' 'true'; - - # Handle CORS preflight requests - if ($request_method = 'OPTIONS') { - add_header 'Access-Control-Allow-Origin' $allow_origin always; - add_header 'Access-Control-Allow-Methods' 'POST, GET, OPTIONS' always; - add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization' always; - add_header 'Access-Control-Allow-Credentials' 'true' always; - add_header 'Access-Control-Max-Age' 1728000; - add_header 'Content-Type' 'text/plain; charset=utf-8'; - add_header 'Content-Length' 0; - return 204; - } - proxy_cache my_cache; proxy_cache_revalidate on; proxy_cache_min_uses 2; @@ -94,12 +68,6 @@ server { location ~* \.(mp3|wav|ogg|flac|aac|aif|webm)$ { proxy_pass http://{{ $.APP }}-{{ $upstream_port }}; - # Add CORS headers for audio files - add_header 'Access-Control-Allow-Origin' $allow_origin always; - add_header 'Access-Control-Allow-Methods' 'GET, POST, 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; - add_header 'Access-Control-Allow-Credentials' 'true' always; }