2014-10-21 3 views
0

I m writting Ionic app. I m PouchDB를 로컬 저장소로 사용하고 이러한 데이터를 원격 CouchDB 서버 iriscouch.com에 복제하려고합니다.하지만 작동시키지 못합니다. db를 복제하려고 할 때 아래와 같은 오류가 발생합니다. 내 노트북에 서버 localy를 시작하면 자격 증명없이 작동합니다.PouchDB to CouchDB replication Ionic 앱

var db = new PouchDB('db'); 

db.replicate.to('https://username:[email protected]:5984/db', {xhrFields:{withCredentials:true}}) 
     //.on('change', function (info) { 
      // handle change 
      // console.log("change"); 
     // console.log(info); 
     .on('uptodate', function (info) { 
      // handle up-to-date 
      console.log("uptodate"); 
      console.log(info); 
     }).on('error', function (err) { 
      // handle error 
      console.log("error"); 
      console.log(err); 
     }); 

옵션 https://username.iriscouch.com:5984/db/?_nonce=VFSibfdoxcnjKz3V 순 :: ERR_CONNECTION_CLOSED pouchdb.js : 5150

CustomPouchError {메시지 : 정의되지 않은 상태 : 405,하는 statusText : "방법이 허용되지 않음"이름 : "UNKNOWN_ERROR"오류 : 사실 ... } services.js : 내 CouchDB를 24

설정

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, content-type, origin, referer"' 

는 그것이 작동되도록하려면 다음

,
var remoteUrl = 'https://username.iriscouch.com/dbname' 
var remote = new PouchDB(remoteUrl, { 
Auth: { 
    username: 'username', 
    password: 'password' 
}, 
live:true, 
withCredentials: true 

});

답변

3

405는 CORS 오류입니다. CORS가 올바르게 설정되지 않았다는 의미입니다. 이거 해봤 니?

1

https://github.com/pouchdb/add-cors-to-couchdb 내가 같은 문제를했고 추가하여 문제를 해결할 수 있었다 헤더에 "X-CSRF 토큰"는 고르에서 설정 iriscouch 구성 섹션을 참조하십시오. 내 헤더 설정합니다

:

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

나는이 다른 사람을 도움이되기를 바랍니다.

+0

어디에 있나요? – bryan

관련 문제