我嘗試將數據庫從PouchDB複製到CouchDB時遇到問題。 擺脫CouchDB中的CORS?
這裏是我使用的數據庫複製代碼
var db = new PouchDB('todos');
var remoteCouch = 'http://localhost:5984/db/';
function sync() {
var opts = {live: true};
db.replicate.to(remoteCouch, opts);
};
我嘗試將數據庫從PouchDB複製到CouchDB時遇到問題。 擺脫CouchDB中的CORS?
這裏是我使用的數據庫複製代碼
var db = new PouchDB('todos');
var remoteCouch = 'http://localhost:5984/db/';
function sync() {
var opts = {live: true};
db.replicate.to(remoteCouch, opts);
};
編輯:現在有一個add-cors-to-couchdb腳本,使這個死簡單:
npm install -g add-cors-to-couchdb && add-cors-to-couchdb
正如PouchDB記錄getting started guide,啓用您需要做的CORS:
$ export HOST=http://username:[email protected] $ curl -X PUT $HOST/_config/httpd/enable_cors -d '"true"' $ curl -X PUT $HOST/_config/cors/origins -d '"*"' $ curl -X PUT $HOST/_config/cors/credentials -d '"true"' $ curl -X PUT $HOST/_config/cors/methods -d '"GET, PUT, POST, HEAD, DELETE"' $ curl -X PUT $HOST/_config/cors/headers -d \ '"accept, authorization, content-type, origin"'
我們也在common errors中記錄了這一點,但顯然它的Googlability仍然不夠高。 :)
注意所有在debian/ubuntu上通過軟件包管理器安裝couchdb。截至今天(2014年10月10日),您將獲得的版本是1.2,並且不支持CORS選項。如果你想使用它們,你必須安裝源代碼版本。我花了一些時間才意識到爲什麼我的CORS設置不起作用,原因是我通過apt-get install couchdb安裝了它,它的版本是1.2。 – szydan