apache / couchdb-nano

Nano: The official Apache CouchDB library for Node.js
https://www.npmjs.com/package/nano
Apache License 2.0
651 stars 165 forks source link

connect to couchdb with curl works and with nano fails #216

Closed hmdevelopermind closed 4 years ago

hmdevelopermind commented 4 years ago

Hello everyone,

connecting to couch using curl returns:

http://4b03SQKEIPqrC3U07eRV:PkPcSbstE4KHX3oLZID5@default-couch.apps.xxx.com
{"couchdb":"Welcome","version":"3.0.0","git_sha":"03a77db6c","uuid":"d118f924612337b166a2c8dfbbdc9177","features":["search","access-ready","partitioned","pluggable-storage-engines","reshard","scheduler"],"vendor":{"name":"The Apache Software Foundation"}} 

However the same set up(password,username and url ) returns:

Unable to connect to Couchdb.

and here is my code:

   private getCouchDBClient(config: CouchConfig): { db: any, endpoint: string } {
        this._logger.info({log: `Setting up couchdb client for:${config.url}`});
        let nano: Nano.ServerScope;
        let db: any;
        try {
            const [proto, path] = config.url.split("://", 2);
            const url = `${proto}://${config.username}:${config.password}@${path}`;
            nano = Nano(url);
            if (config.dbName && config.dbName.length > 1) {
                db = nano.db.use(config.dbName);
            } else {
                db = nano.db;
            }
        } catch (err) {
            this._logger.debug({ log: COUCH_CONNECTION_ERROR.message });
            this._logger.debug({ log: `Error: ${err}` });
            throw (new Error(COUCH_CONNECTION_ERROR.message));
        }

        return {
            db: db,
            endpoint: `${config.url}/${config.dbName}`,
        };

    }

and my env file:

SEARCH_RECORDS_DATASTORE_TYPE = 'couchdb'
SEARCH_RECORDS_COUCH_USERNAME = '4b03SQKEIPqrC3U07eRV'
SEARCH_RECORDS_COUCH_PASSWORD = 'PkPcSbstE4KHX3oLZID5'
SEARCH_RECORDS_COUCH_DB_NAME = 'de-search-records'
SEARCH_RECORDS_COUCH_URL ='http://default-couch.app.xxx.com'

Any idea?

glynnbird commented 4 years ago

If you just want to check connectivity. A simpler test script should help you identify what's going on. This is the equivalent of the curl statement:

const Nano = require('nano')
const nano = Nano('http://4b03SQKEIPqrC3U07eRV:PkPcSbstE4KHX3oLZID5@default-couch.app.xxx.com')
const db = nano.db.use('de-search-records')
db.info().then(console.log)

^ this works with Nano for local CouchDB on http or remote Cloudant over https.

I don't see that the code you supplied actually makes any API calls. db.use doesn't nor does the 'constructor'.

hmdevelopermind commented 4 years ago

@glynnbird Thanks a lot for your comment. Actually I noticed there was a empty space in my path url and that was causing the issue