- Start thor without
--api-cors
- Add
Access-Control
related headers for HTTP preflight requests - Remove
Origin
for allowed WebSocket connections
Last active
July 21, 2021 02:49
-
-
Save libotony/851b09f9a1a3da935b419e6fe636f9aa to your computer and use it in GitHub Desktop.
PUBLIC THOR NODE WITH NGINX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map $http_upgrade $connection_upgrade { | |
default upgrade; | |
"" close; | |
} | |
upstream BACKEND { | |
server 127.0.0.1:8669; | |
keepalive 64; | |
} | |
server { | |
listen 80; | |
server_name server.domain.dev; | |
add_header "Access-Control-Allow-Origin" $http_origin always; | |
add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, HEAD" always; | |
add_header "Access-Control-Allow-Headers" "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,x-genesis-id" always; | |
add_header "Access-Control-Expose-Headers" "x-genesis-id,x-thorest-ver" always; | |
add_header "Access-Control-Max-Age" 86400 always; | |
if ($request_method = "OPTIONS" ) { | |
return 204 no-content; | |
} | |
location ^~ /subscriptions { | |
proxy_redirect off; | |
proxy_read_timeout 1m; | |
proxy_connect_timeout 1m; | |
proxy_pass http://BACKEND; | |
proxy_http_version 1.1; | |
proxy_set_header Host $host; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection $connection_upgrade; | |
proxy_set_header Origin ""; | |
} | |
location / { | |
proxy_redirect off; | |
proxy_read_timeout 1m; | |
proxy_connect_timeout 1m; | |
proxy_pass http://BACKEND; | |
proxy_http_version 1.1; | |
proxy_set_header Host $host; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection ""; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map $http_upgrade $connection_upgrade { | |
default upgrade; | |
"" close; | |
} | |
map $http_origin $origin_allowed { | |
default 0; | |
"http://allow.domain.dev" 1; | |
} | |
map $origin_allowed $cors_allow_origin { | |
default ""; | |
1 $http_origin; | |
} | |
map $origin_allowed $cors_allow_methods { | |
default ""; | |
1 "GET, POST, OPTIONS, HEAD"; | |
} | |
map $origin_allowed $cors_allow_headers { | |
default ""; | |
1 "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,x-genesis-id"; | |
} | |
map $origin_allowed $cors_expose_headers { | |
default ""; | |
1 "x-genesis-id,x-thorest-ver"; | |
} | |
map $origin_allowed $cors_max_age { | |
default ""; | |
1 86400; | |
} | |
map $origin_allowed $websocket_origin { | |
default $http_origin; | |
1 ""; | |
} | |
upstream BACKEND { | |
server 127.0.0.1:8669; | |
keepalive 64; | |
} | |
server { | |
listen 80; | |
server_name server.domain.dev; | |
add_header "Access-Control-Allow-Origin" $cors_allow_origin always; | |
add_header "Access-Control-Allow-Methods" $cors_allow_methods always; | |
add_header "Access-Control-Allow-Headers" $cors_allow_headers always; | |
add_header "Access-Control-Expose-Headers" $cors_expose_headers always; | |
add_header "Access-Control-Max-Age" $cors_max_age always; | |
if ($request_method = "OPTIONS" ) { | |
return 204 no-content; | |
} | |
location ^~ /subscriptions { | |
proxy_redirect off; | |
proxy_read_timeout 1m; | |
proxy_connect_timeout 1m; | |
proxy_pass http://BACKEND; | |
proxy_http_version 1.1; | |
proxy_set_header Host $host; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection $connection_upgrade; | |
proxy_set_header Origin $websocket_origin; | |
} | |
location / { | |
proxy_redirect off; | |
proxy_read_timeout 1m; | |
proxy_connect_timeout 1m; | |
proxy_pass http://BACKEND; | |
proxy_http_version 1.1; | |
proxy_set_header Host $host; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment