0

I've been trying to get cloudant local going for a couple of hours. I've installed via docker as described here

I can access the dashboard on localhost:8080 with the default creds. And I can curl the DB when I supply same creds e.g. curl -X PUT $HOST/database -u admin:pass

The problem is, when I connect with the nodejs-cloudant module I always get 401 - Unauthorised errors, specifically:

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

It seems that the issue is that there is no user being returned when cloudant local connects. When I connect to my cloud based cloudant instance, the reply.userCtx is populated, however when connecting locally it is: userCtx: { name: null, roles: [] } }

The actual login seems to be working though as I've tested with incorrect creds.

This is where I am setting the credentials:

    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)

4

1 回答 1

1

如果您提供这样的网址:

var url="http://admin:pass@localhost:8080";
this.cloudant = cloudant({ url: url, plugin: "promises"});

然后它工作正常。

问题是当您说时account = 'admin',该库假定主机名为admin.cloudant.com. 如果您提供完整的 URL,那么它是明确的并且可以完美运行。

希望这可以帮助。

于 2017-08-21T07:01:23.300 回答