Skip to content

Instantly share code, notes, and snippets.

@hiiamyes
Last active March 5, 2020 17:06
Show Gist options
  • Save hiiamyes/09f7a6431f83289c3782ce790092d89d to your computer and use it in GitHub Desktop.
Save hiiamyes/09f7a6431f83289c3782ce790092d89d to your computer and use it in GitHub Desktop.
Nginx CORS proxy
server {
listen 3003;
server_name localhost;
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization, Cache-Control, Cookie, If-Modified-Since, Range, User-Agent, X-Requested-With';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, PATCH';
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 != 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization, Cache-Control, Cookie, If-Modified-Since, Range, User-Agent, X-Requested-With';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, PATCH';
}
proxy_redirect off;
proxy_pass http://host.docker.internal:3001;
}
}
server {
listen 3003;
server_name localhost;
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' *;
add_header 'Access-Control-Allow-Headers' *;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, PATCH';
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 != 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' *;
add_header 'Access-Control-Allow-Headers' *;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, PATCH';
}
proxy_redirect off;
proxy_pass http://host.docker.internal:3001;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment