【问题标题】:CORS issue with CouchDB + credentials + origin wildcardCouchDB + 凭证 + 原始通配符的 CORS 问题
【发布时间】:2017-03-12 00:05:22
【问题描述】:
我正在尝试在 flow.ch 上从 Cloudant 迁移到 Jelastic。在本地测试(离子服务)时,我收到 pouchdb 的 CORS 错误。
除了我缺少的 CouchDB 之外,Jelastic 中还有其他配置吗?
XMLHttpRequest 无法加载 http://xxx.flow.ch/xxx。对预检请求的响应未通过访问控制检查:当请求的凭据模式为“包含”时,响应中的“Access-Control-Allow-Origin”标头的值不得为通配符“*”。因此,Origin 'http://localhost:8100' 不允许访问。 XMLHttpRequest 发起的请求的凭证模式由 withCredentials 属性控制。
我在 Jelastic 上配置了一个 CouchDB 并激活了 CORS。
通过 CURL 正常访问有效。从 Cloudant 复制到 Jelastic 也同样有效。
我尝试使用 Chrome 扩展来启用“Allow-Control-Allow-Origin: *”
【问题讨论】:
标签:
cors
ionic2
couchdb
jelastic
【解决方案1】:
couchdb docs say this:
你不能同时设置origins = *和credentials = true选项
因此,如果您希望带有凭据的跨域请求与 couchdb 一起使用,则必须将 origins 值设置为允许的来源的显式列表;例如:
[cors]
origins = http://localhost, https://localhost, http://couch.mydev.name:8080
【讨论】:
-
它不是 CouchDB 特定的。它实际上是 CORS 的规范。因此,没有设置 CORS 的服务器端系统允许这样做