PouchDB基本身份验证不适用于同步网关

时间:2017-06-06 12:12:44

标签: node.js reactjs couchbase pouchdb couchbase-sync-gateway

当我尝试使用同步网关从PouchDB同步到couchbase服务器时,我收到以下错误:

  

XMLHttpRequest无法加载"thumbs up"。请求标头字段预检响应中的Access-Control-Allow-Headers不允许授权。

我尝试设置标题,即使那时我也无法摆脱这个错误。 这是我的同步网关配置文件

sync-gateway-config.json::

    {
        "log":["*"],
        "databases": {
            "buildercycle": {
                "server":"http://localhost:8091",
                "bucket": "default",
                "users": {
                    "GUEST": {
                        "disabled": false,
                        "admin_channels": ["*"]
                    }
                },
                "sync":`function(doc, oldDoc) {
                      if (doc.type == "sports"){
                        channel(doc.type);
                        access(doc.owner,doc.type);

                      } else  {
                        channel(doc.type);
                       access(doc.owner,doc.type);
                      } 
                }`

            }
        },
        "CORS": {
            "Origin": ["http://localhost:8000","http://localhost:8083", "http://localhost:4985"],
            "LoginOrigin": ["http://localhost:8000","http://localhost:8083","http://localhost:4985"],
            "Headers": ["Content-Type"],
            "MaxAge": 17280000
        }
    }

    I am trying to sync my PouchDB in following way:
    remoteCouch="http://"+user+":"+pass+"@localhost:4984/buildercycle";
                            console.log(remoteCouch);
      var opts = {live: true,withCredentials: true};
      db.sync(remoteCouch,opts,'error');


    i am passing user(user1) and password(password) which is defined in following sync_gateway admin URL

http://localhost:4984/test/

我无法确定错误,请帮助

1 个答案:

答案 0 :(得分:1)

在标题中添加授权

“标题”:[“内容类型”,“授权”],

我认为在你的情况下,cors标题没有正确设置。