2017-08-21 20 views
0

我一直在试图让云端本地进行几个小时。我已经通过码头安装如上所述here未经授权的管理员在Cloudant本地使用nodejs-cloudant(nano)

我可以访问仪表板localhost:8080与默认creds。当我提供相同的信用信号时,我可以蜷缩数据库,例如curl -X PUT $HOST/database -u admin:pass

的问题是,当我与nodejs-cloudant模块连接我总是得到401 - 未授权的错误,特别是:

{ error: 'unauthorized', reason: 'one of _all_dbs, _admin, server_admin is required for this request', statusCode: 401 }

看来,问题是,有没有用户时cloudant返回本地连接。当我连接到基于云的cloudant实例时,reply.userCtx已填充,但是在本地连接时:userCtx: { name: null, roles: [] } }

实际登录似乎正在工作,因为我测试了不正确的信用。

这是我设置的凭据:

const credentials = { 
 
     account: (stage === 'local') ? 'admin' : db.credentials.username, 
 
     password: (stage === 'local') ? 'pass' : db.credentials.password, 
 
     plugin: 'promises', 
 
    } 
 
    if (stage === 'local') { 
 
     credentials.url = 'http://localhost:8080' 
 
    } 
 
    this.cloudant = cloudant(credentials)

任何帮助将不胜感激,谢谢!

回答

1

如果提供的URL是这样的:

var url="http://admin:[email protected]:8080"; 
this.cloudant = cloudant({ url: url, plugin: "promises"}); 

然后正常工作。

问题是,当你说account = 'admin'时,库假定主机名为admin.cloudant.com。如果你提供完整的URL,那么它是明确的,并且完美地工作。

希望这会有所帮助。

+0

感谢堆,运作良好!这意味着我不必在多余的帐户和密码字段中正确传递? – theSiberman