diff --git a/salt/application/snipt.nginx.conf b/salt/application/snipt.nginx.conf index ce24220..b91e29c 100644 --- a/salt/application/snipt.nginx.conf +++ b/salt/application/snipt.nginx.conf @@ -47,14 +47,41 @@ upstream backend_snipt { } location / { + + # Open CORS config from https://gist.github.com/michiel/1064640. + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Credentials' 'true'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain charset=UTF-8'; + add_header 'Content-Length' 0; + return 204; + } + if ($request_method = 'POST') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Credentials' 'true'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + } + if ($request_method = 'GET') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Credentials' 'true'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + } + rewrite_by_lua ' if string.find(ngx.var.host, "_") then local newHost, n = ngx.re.gsub(ngx.var.host, "_", "-") ngx.redirect(ngx.var.scheme .. "://" .. newHost .. ngx.var.uri) end '; + proxy_pass http://backend_snipt; proxy_set_header Host $host; + } location /static/ {