couch-client icon indicating copy to clipboard operation
couch-client copied to clipboard

Works on localhost, crashes using Cloudant

Open dethe opened this issue 14 years ago • 7 comments

Using the same database works find on local, but when replicated to Cloudant the connection crashes Node.js with an exception:

undefined:1

SyntaxError: Unexpected token ILLEGAL at Object.parse (native) at IncomingMessage. (/usr/local/Cellar/node/0.2.3/lib/node/.npm/couch-client/0.0.1/package/lib/couch-client.js:86:45) at IncomingMessage.emit (events:41:20) at HTTPParser.onMessageComplete (http:107:23) at Client.onEnd as onend at IOWatcher.callback (net:472:28) at node.js:768:9

I can connect to the db using curl and retrieve data, and Node's JSON module can parse the data retrieved by curl just fine, so I'm not sure what's going on.

dethe avatar Oct 19 '10 17:10 dethe

Interesting. Any idea if the bug is in my code, node itself, or something cloudent it doing wrong?

Can you trace the data going back and forth using pcap or something?

creationix avatar Oct 19 '10 18:10 creationix

I've dug into it further. There are several things going on. The unexpected token is because the server is returning

<html><body><h1>503 Service Unavailable</h1> No server is available to handle this request. </body></html>

when called by CouchClient.

CouchClient also assumes port 5984, and Cloudant is running on port 80, so I need to specify port 80 in my connection url, where curl assumes port 80.

Finally, CouchClient seems to throw away information about secure sockets, so it is not connecting over https.

I've gotten far enough to bring Node and CouchClient up, but it appears to be unresponsive now, will give you some more info when I get it.

dethe avatar Oct 19 '10 18:10 dethe

I think I am having a similar issue. I can connect to a CouchDB instance locally, but using Cloudant via heroku over https fails. If I curl my couchdb running on cloudant, I can connect to the database. However, attempting to do the same with CouchClient gives me this:

2011-06-07T14:45:12+00:00 app[web.1]: node.js:134 2011-06-07T14:45:12+00:00 app[web.1]: throw e; // process.nextTick error, or 'error' event on first tick 2011-06-07T14:45:12+00:00 app[web.1]: ^ 2011-06-07T14:45:12+00:00 app[web.1]: TypeError: Cannot read property 'rows' of undefined 2011-06-07T14:45:12+00:00 app[web.1]: at /app/node_modules/couch-client/lib/couch-client.js:170:21 2011-06-07T14:45:12+00:00 app[web.1]: at ClientRequest.errorHandler (/app/node_modules/couch-client/lib/couch-client.js:47:23) 2011-06-07T14:45:12+00:00 app[web.1]: at ClientRequest.emit (events.js:64:17) 2011-06-07T14:45:12+00:00 app[web.1]: at CleartextStream. (http.js:1272:31) 2011-06-07T14:45:12+00:00 app[web.1]: at CleartextStream.emit (events.js:61:17) 2011-06-07T14:45:12+00:00 app[web.1]: at Array. (tls.js:617:22) 2011-06-07T14:45:12+00:00 app[web.1]: at EventEmitter._tickCallback (node.js:126:26)

mhemesath avatar Jun 07 '11 14:06 mhemesath

I'm seeing the same issue as @mhemesath

jhollingworth avatar Jun 22 '11 15:06 jhollingworth

I got around it by doing this:

 new CouchClient(process.env.CLOUDANT_URL + ":443/myDocument")

mhemesath avatar Jun 22 '11 15:06 mhemesath

awesome, that worked :) thanks!

jhollingworth avatar Jun 22 '11 16:06 jhollingworth

I logged an issue specific to this problem here: https://github.com/creationix/couch-client/issues/29

mhemesath avatar Jun 22 '11 17:06 mhemesath