I wrote a page and it can be visited in sheyh.cn/multi/#/singleText.
I tried to make a request to https://aip.baidubce.com/oauth/
, It works properly in Vue devserver proxy and the config is like this
devServer: {
port: "8082",
proxy: {
"/oauth": {
target: "https://aip.baidubce.com",
changeOrigin: true,
secure: false,
},
},
},
After I upload the file to server the CORS error occured.
Then I tried to config my Nginx proxy like this.
#PROXY-START/multi
location /oauth/
{
add_header Access-Control-Allow-Origin '*';
add_header Access-Control-Allow-Methods 'POST,PUT,GET,DELETE';
proxy_pass https://aip.baidubce.com/;
proxy_set_header Host aip.baidubce.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_http_version 1.1;
# proxy_hide_header Upgrade;
add_header X-Cache $upstream_cache_status;
#Set Nginx Cache
set $static_filefFIlksdb 0;
if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
{
set $static_filefFIlksdb 1;
expires 1m;
}
if ( $static_filefFIlksdb = 0 )
{
add_header Cache-Control no-cache;
}
}
#PROXY-END/
The error is still there
Access to XMLHttpRequest at 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=DiChTG01AUDydg4gUfb88f03&client_secret=zdU2g9ZLAG9w2owWgwPEaGfGUrWHmB8j' from origin 'https://sheyh.cn' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I've added Access-Control-Allow-Origin in my config, but it doesn't work properly.