Access-Control-Allow-Origin error sending a jQuery Post to Google API's

前端 未结 7 1724
小蘑菇
小蘑菇 2020-11-22 14:04

I read a lot for the \'Access-Control-Allow-Origin\' error, but I don\'t understand what I have to fix :(

I\'m playing with Google Moderator API, but when I try to a

7条回答
  •  情深已故
    2020-11-22 14:31

    If you have this error trying to consume a service that you can't add the header Access-Control-Allow-Origin * in that application, but you can put in front of the server a reverse proxy, the error can avoided with a header rewrite.

    Assuming the application is running on the port 8080 (public domain at www.mydomain.com), and you put the reverse proxy in the same host at port 80, this is the configuration for Nginx reverse proxy:

    server {
        listen      80;
        server_name www.mydomain.com;
        access_log  /var/log/nginx/www.mydomain.com.access.log;
        error_log   /var/log/nginx/www.mydomain.com.error.log;
    
        location / {
            proxy_pass   http://127.0.0.1:8080;
            add_header   Access-Control-Allow-Origin *;
        }   
    }
    

提交回复
热议问题