Skip to content

Commit 53970a1

Browse files
authored
Add config for leaderboard (#45)
Redirect /leaderboard/* to leaderboard service running on port 8282 Add config to solve CORS issues See also: https://github.com/uspgamedev/leaderboard
1 parent cfab24c commit 53970a1

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

default.conf

+38
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,44 @@ server {
8686
include /etc/nginx/shared/proxy.conf;
8787
}
8888

89+
location /leaderboard {
90+
91+
# Solve CORS issues (sources: https://enable-cors.org/server_nginx.html https://michielkalkman.com/snippets/nginx-cors-open-configuration/)
92+
if ($request_method = 'OPTIONS') {
93+
add_header 'Access-Control-Allow-Origin' '*';
94+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
95+
#
96+
# Custom headers and headers various browsers *should* be OK with but aren't
97+
#
98+
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
99+
#
100+
# Tell client that this pre-flight info is valid for 20 days
101+
#
102+
add_header 'Access-Control-Max-Age' 1728000;
103+
add_header 'Content-Type' 'text/plain; charset=utf-8';
104+
add_header 'Content-Length' 0;
105+
return 204;
106+
}
107+
if ($request_method = 'POST') {
108+
add_header 'Access-Control-Allow-Origin' '*' always;
109+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
110+
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
111+
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
112+
}
113+
if ($request_method = 'GET') {
114+
add_header 'Access-Control-Allow-Origin' '*' always;
115+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
116+
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
117+
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
118+
}
119+
120+
proxy_pass http://172.17.0.1:8282;
121+
proxy_http_version 1.1;
122+
proxy_set_header Upgrade $http_upgrade;
123+
proxy_set_header Connection "upgrade";
124+
include /etc/nginx/shared/proxy.conf;
125+
126+
}
89127

90128
location /metrics {
91129
auth_basic "Metrics";

0 commit comments

Comments
 (0)