CORS error in PouchDB with CORS enabled in CouchDB

戏子无情 提交于 2019-12-11 05:53:54

问题


I have CORS enabled in CouchDB:

I run the app on Windows 8.1, serving it with hapi.js.

When viewing it in Chrome after a while this error message appears in the console:

Uncaught (in promise) CustomPouchError {status: 500, name: "unknown_error", message: "Database encountered an unknown error", error: true, toString: function}

Firefox aborts accessing CouchDB, for instance: http://127.0.0.1:5984/user_z_at_z_p_ch/?_nonce=1431328831527, then reports that a cross origin request was blocked.

I have tried to run add-cors-to-couchdb but I get this error:

PS C:\Users\alex> add-cors-to-couchdb
events.js:85
      throw er; // Unhandled 'error' event
        ^
Error: read ECONNRESET
    at exports._errnoException (util.js:746:11)
    at TCP.onread (net.js:559:26)

回答1:


Your CORS settings look correct. Are you sure your CouchDB is externally accessible from the hostname/port you're using?

If add-cors-to-couchdb is failing, it's because the default CouchDB at localhost:5984 is inaccessible. It has options to specify a CouchDB at another URL.




回答2:


it seems that I missed one header in the cors section of config.ini in couchdb: x-csrf-token

cors now works with these headers:

accept, authorization, content-type, origin, referer, x-csrf-token

I have no idea why this happens but hey: it works



来源:https://stackoverflow.com/questions/30161843/cors-error-in-pouchdb-with-cors-enabled-in-couchdb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!