{"action":"opened","issue":{"url":"https://api.github.com/repos/cloudant/nodejs-cloudant/issues/141","repository_url":"https://api.github.com/repos/cloudant/nodejs-cloudant","labels_url":"https://api.github.com/repos/cloudant/nodejs-cloudant/issues/141/labels{/name}","comments_url":"https://api.github.com/repos/cloudant/nodejs-cloudant/issues/141/comments","events_url":"https://api.github.com/repos/cloudant/nodejs-cloudant/issues/141/events","html_url":"https://github.com/cloudant/nodejs-cloudant/issues/141","id":164514602,"number":141,"title":"reconfigure.js does not correctly handle Bluemix accounts","user":{"login":"l2fprod","id":12746550,"avatar_url":"https://avatars.githubusercontent.com/u/12746550?v=3","gravatar_id":"","url":"https://api.github.com/users/l2fprod","html_url":"https://github.com/l2fprod","followers_url":"https://api.github.com/users/l2fprod/followers","following_url":"https://api.github.com/users/l2fprod/following{/other_user}","gists_url":"https://api.github.com/users/l2fprod/gists{/gist_id}","starred_url":"https://api.github.com/users/l2fprod/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/l2fprod/subscriptions","organizations_url":"https://api.github.com/users/l2fprod/orgs","repos_url":"https://api.github.com/users/l2fprod/repos","events_url":"https://api.github.com/users/l2fprod/events{/privacy}","received_events_url":"https://api.github.com/users/l2fprod/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-08T11:48:01Z","updated_at":"2016-07-08T11:48:01Z","closed_at":null,"body":"In Bluemix, Cloudant service usernames are like \"xxxxxxxx-bluemix\" and hosts like \"xxxxxxxx-bluemix.cloudant.com\"\r\n\r\nHowever if I initialize Cloudant with:\r\n```\r\nvar cloudant = require('cloudant')({\r\n  account: \"1234-4567-bluemix.cloudant.com\",\r\n  password: \"a0a893028302839382028302830\"\r\n});\r\n```\r\n\r\nWhen I try to query a db it fails with error 503. The error shows it tries to access bluemix.cloudant.com:\r\n```\r\n     uri: 'https://XXXXXX:XXXXXX@bluemix.cloudant.com/openwhisk-darkvision/_all_docs' },\r\n```\r\n\r\nBasically it did not correctly extract the account name from the hostname I gave which it should be able to do according to the header in reconfigure.js:\r\n\r\n```\r\n// reconfigure deals with the various ways the credentials can be passed in \r\n// and returns an full URL\r\n// e.g. { account:\"myaccount\", password: \"mypassword\"}\r\n// or   { key: \"mykey\", password: \"mykey\", account:\"myaccount\"}\r\n// or   { key: \"mykey\", password: \"mykey\", account:\"myaccount\"}\r\n// or   { account:\"myaccount.cloudant.com\", password: \"mykey\"}\r\n// or   { account: \"myaccount\"}\r\n// or   { url: \"https://mykey:mypassword@myaccount.cloudant.com\"}\r\n```\r\n\r\nSeems like the regexp https://github.com/cloudant/nodejs-cloudant/blob/master/lib/reconfigure.js#L46\r\n```\r\nconfig.account.match(/(\\w+)\\.cloudant\\.com/);\r\n```\r\ndoes not correctly handle the \"-\" in the hostname.\r\n\r\nThe simple workaround is to initialize Cloudant with the username, not the host, even if reconfigure.js was supposed to handle it. This works:\r\n```\r\nvar cloudant = require('cloudant')({\r\n  account: \"1234-4567-bluemix\",\r\n  password: \"a0a893028302839382028302830\"\r\n});\r\n```"}}
{"actor":{"display_login":"l2fprod"}}