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)
If you supply the url like this:
var url="http://admin:pass@localhost:8080";
this.cloudant = cloudant({ url: url, plugin: "promises"});
then it works fine.
The problem is when you say account = 'admin'
, the library assumes a hostname of admin.cloudant.com
. If you supply the full URL, then it is unambiguous and works perfectly.
Hope this helps.