alexfigtree / CoreID

For MIT Human Dynamics group blockchain-backed individual identity open source prototype
MIT License
4 stars 5 forks source link

nginx server to proxy with cors header #37

Closed akscanb closed 7 years ago

akscanb commented 7 years ago

I tried to utilize a nginx server to proxy all my from the react app to my bitcoin server, but it seems that did not work as intended. Below is the nginx configuration I added which can be found in /usr/nginx/sites-available/default

server { listen 80; server_name localhost;

location /g/ {
proxy_pass http://www.google.com/;
}

location /so/ {

proxy_pass http://stackoverflow.com/;
}

location / {  # I tried putting it before other locations too

proxy_pass http://www.google.com/; # added here also, for tests, tried putting it just after headers too

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-CustomHeader,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 = 'GET') { # let's add them for all methods
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-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
# }

}

}

akscanb commented 7 years ago

CORS isn't resolved, but we currently have a work around for it so this issue will be closed