creationix / couch-client

A minimal CouchDB client that easy and powerful
MIT License
101 stars 9 forks source link

Works on localhost, crashes using Cloudant #2

Open dethe opened 13 years ago

dethe commented 13 years ago

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.

creationix commented 13 years ago

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?

dethe commented 13 years ago

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.

mhemesath commented 13 years ago

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)

jhollingworth commented 13 years ago

I'm seeing the same issue as @mhemesath

mhemesath commented 13 years ago

I got around it by doing this:

 new CouchClient(process.env.CLOUDANT_URL + ":443/myDocument")
jhollingworth commented 13 years ago

awesome, that worked :) thanks!

mhemesath commented 13 years ago

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