【发布时间】:2016-04-02 00:33:49
【问题描述】:
我在http://localhost:8100 上运行一个离子应用程序,它连接到我在http://localhost:3000 上运行的快递后端。
像往常一样,我面临着 CORS 问题。在 chrome 中禁用网络安全并没有帮助。
chrome报告的错误是:
(index):1 XMLHttpRequest cannot load http://localhost:3000/auth/facebook.
Response to preflight request doesn't pass access control check:
Credentials flag is 'true',
but the 'Access-Control-Allow-Credentials' header is ''.
It must be 'true' to allow credentials.
Origin 'http://localhost:8100' is therefore not allowed access.
Remote Address:[::1]:3000
Request URL:http://localhost:3000/auth/facebook
Request Method:OPTIONS
Status Code:200 OK
Response Headers
view source
Access-Control-Allow-Headers:accept, content-type
Access-Control-Allow-Methods:POST
Access-Control-Allow-Origin:http://localhost:8100
Access-Control-Max-Age:31536000
Connection:keep-alive
Content-Length:2
Content-Type:text/plain; charset=utf-8
Date:Wed, 04 Nov 2015 02:25:07 GMT
ETag:W/"2-d736d92d"
X-Powered-By:Express
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, content-type
Access-Control-Request-Method:POST
Connection:keep-alive
DNT:1
Host:localhost:3000
Origin:http://localhost:8100
Referer:http://localhost:8100/
第一个问题是: 我在请求标头中没有看到任何 Access-Controll-Allow-Credentials 标志,那么为什么 chrome 会抱怨
第二个问题: 我曾尝试使用 CORS express 模块,但这并没有帮助。我该如何克服这个问题?
【问题讨论】:
-
你自己能找到答案吗?如果是这样,请写下答案,以便像我这样的其他人可以从中受益 X)
-
@RicardoPanaggio .. 已发布答案