@@ -3,26 +3,47 @@ events {
33}
44
55http {
6- # Nginx will handle gzip compression of responses from the app server
6+ # Map only allows your geode-solutions.com domains (including next.vease.geode-solutions.com)
7+ map $http_origin $allow_origin {
8+ ~ ^https://( .*\.)?geode-solutions\.com$ $http_origin ;
9+ default "" ;
10+ }
11+
712 gzip on;
813 gzip_proxied any;
914 gzip_types text/plain application/json;
1015 gzip_min_length 1000 ;
1116
1217 server {
13- listen 443 ssl ;
18+ listen 80 ;
1419 server_name localhost;
15-
16- ssl_certificate nginx.crt;
17- ssl_certificate_key nginx.key;
18-
1920 client_max_body_size 0;
2021
21- location ~ "^/[a-z0-9]{32}/geode/" {
22- if ( $request_method !~ ^( DELETE|GET|POST|PUT|OPTIONS) $) {
23- return 405 ;
22+ # ====================== /geode/ location ======================
23+ location ~ "^/geode/" {
24+ # Preflight OPTIONS - handled by nginx (fast, no hit to Flask)
25+ if ( $request_method = 'OPTIONS' ) {
26+ add_header 'Access-Control-Allow-Origin' $allow_origin always;
27+ add_header 'Access-Control-Allow-Credentials' 'true' always;
28+ add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, PATCH, OPTIONS' always;
29+ 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;
30+ add_header 'Access-Control-Max-Age' 1728000 always; # 20 days
31+ add_header 'Content-Type' 'text/plain; charset=utf-8' ;
32+ add_header 'Content-Length' 0;
33+ return 204 ;
2434 }
25- rewrite "^/[a-z0-9]{32}/geode/(.*)" /$1 break ;
35+
36+ # Normal requests
37+ limit_except DELETE GET POST PUT OPTIONS { deny all; }
38+
39+ add_header 'Access-Control-Allow-Origin' $allow_origin always;
40+ add_header 'Access-Control-Allow-Credentials' 'true' always;
41+ add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, PATCH, OPTIONS' always;
42+ 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;
43+ add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
44+ add_header 'Vary' 'Origin' always;
45+
46+ rewrite "^/geode/(.*)" /$1 break ;
2647 proxy_pass http ://localhost:5000 ;
2748 proxy_http_version 1.1;
2849 proxy_set_header Host $host ;
@@ -31,20 +52,56 @@ http {
3152 proxy_set_header X-Forwarded-Proto $scheme ;
3253 }
3354
34- location ~ "^/[a-z0-9]{32}/viewer/" {
35- if ( $request_method !~ ^( GET|POST|OPTIONS) $) {
36- return 405 ;
55+ # ====================== /viewer/ location ======================
56+ location ~ "^/viewer/" {
57+ if ( $request_method = 'OPTIONS' ) {
58+ add_header 'Access-Control-Allow-Origin' $allow_origin always;
59+ add_header 'Access-Control-Allow-Credentials' 'true' always;
60+ add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, PATCH, OPTIONS' always;
61+ 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;
62+ add_header 'Access-Control-Max-Age' 1728000 always;
63+ add_header 'Content-Type' 'text/plain; charset=utf-8' ;
64+ add_header 'Content-Length' 0;
65+ return 204 ;
3766 }
38- rewrite "^/[a-z0-9]{32}/viewer/(.*)" /$1 break ;
67+
68+ limit_except GET POST OPTIONS { deny all; }
69+
70+ add_header 'Access-Control-Allow-Origin' $allow_origin always;
71+ add_header 'Access-Control-Allow-Credentials' 'true' always;
72+ add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, PATCH, OPTIONS' always;
73+ 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;
74+ add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
75+ add_header 'Vary' 'Origin' always;
76+
77+ rewrite "^/viewer/(.*)" /$1 break ;
3978 proxy_pass http ://localhost:1234 ;
4079 proxy_http_version 1.1;
4180 proxy_set_header Host $host ;
4281 proxy_set_header X-Real-IP $remote_addr ;
4382 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
4483 proxy_set_header X-Forwarded-Proto $scheme ;
45-
4684 proxy_set_header Connection "keep-alive, Upgrade" ;
4785 proxy_set_header Upgrade websocket;
4886 }
87+
88+ # Catch-all for anything else (optional, returns proper CORS even on 404)
89+ location / {
90+ if ( $request_method = 'OPTIONS' ) {
91+ add_header 'Access-Control-Allow-Origin' $allow_origin always;
92+ add_header 'Access-Control-Allow-Credentials' 'true' always;
93+ add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, PATCH, OPTIONS' always;
94+ 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;
95+ add_header 'Access-Control-Max-Age' 1728000 always;
96+ add_header 'Content-Type' 'text/plain; charset=utf-8' ;
97+ add_header 'Content-Length' 0;
98+ return 204 ;
99+ }
100+
101+ add_header 'Access-Control-Allow-Origin' $allow_origin always;
102+ add_header 'Access-Control-Allow-Credentials' 'true' always;
103+ add_header 'Vary' 'Origin' always;
104+ return 404 ;
105+ }
49106 }
50- }
107+ }
0 commit comments