0

我正在使用带有 nodeJs v6 后端的反应前端和 socket.io-redis pub sub 方法。在这种情况下,浏览器会拒绝连接。
我有这个错误: Failed to load https://api.mydomain.com/socket.io-client/?EIO=3&transport=polling&t=M8vzD5C: The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:3000, *', but only one is allowed. Origin 'http://localhost:3000' is therefore not allowed access. 我在前端反应,后端 nodeJs 上运行,带有 pub sub socket-redis 连接这是我的响应标头: Access-Control-Allow-Credentials: true Access-Control-Allow-Credentials: true Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, If-Modified-Since, Authorization Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS Access-Control-Allow-Origin: http://localhost:3000 Access-Control-Allow-Origin: * Connection: keep-alive Content-Length: 104 Content-Type: text/plain; charset=UTF-8 Date: Sun, 18 Mar 2018 16:19:12 GMT Server: nginx/1.10.3 (Ubuntu) 我可以知道我做错了什么显然可以建立连接,但它会立即中断并且不断尝试重新连接循环(我知道为什么)但是为什么我的响应标头会有多个值?

4

1 回答 1

-1

这就是我在上面的代码中添加的内容:我注释掉了影响套接字请求的 add_headers

set $cors '';
if ($request_uri !~ '^/socket.io-client') {
set $cors 'true';
}

if ($cors = 'true') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
}
于 2018-03-19T15:41:26.577 回答