josephg / node-browserchannel

An implementation of a google browserchannel server in node.js
287 stars 47 forks source link

BrowserChannel CORS not working with ShareJS 0.7 #41

Closed thompsonbill closed 10 years ago

thompsonbill commented 10 years ago

Continued from this issue: https://github.com/share/ShareJS/issues/293

$ curl -D - http://192.168.1.5:7007/channel/
HTTP/1.1 404 Not Found
Content-Type: text/plain
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
X-Content-Type-Options: nosniff
Access-Control-Allow-Origin: *
Date: Sat, 22 Feb 2014 00:27:43 GMT
Connection: keep-alive
Transfer-Encoding: chunked

Not found

$ curl -D - http://192.168.1.5:7007/test?VER=8\&MODE=init\&zx=2zfy3vvc003c\&t=1
HTTP/1.1 404 Not Found
Content-Type: text/html
Date: Sat, 22 Feb 2014 00:29:06 GMT
Connection: keep-alive
Transfer-Encoding: chunked

Cannot GET /test?VER=8&MODE=init&zx=2zfy3vvc003c&t=1
wenzowski commented 10 years ago

this looks like expected behavior for browserchannel, which mounts the socket at /channel by default and therefore communicates through /channel/test and /channel/bind

thompsonbill commented 10 years ago

If I modify the URL ShareJS generates, the header is back there again:

$ curl -D - http://192.168.1.5:7007/channel/test?VER=8\&MODE=init\&zx=2zfy3vvc003c\&t=1
HTTP/1.1 200 OK
Content-Type: text/plain
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
X-Content-Type-Options: nosniff
Access-Control-Allow-Origin: *
X-Accept: application/json; application/x-www-form-urlencoded
Date: Sat, 22 Feb 2014 00:47:43 GMT
Connection: keep-alive
Transfer-Encoding: chunked
josephg commented 10 years ago

ShareJS doesn't generate the URL. ShareJS doesn't care about how your client & server communicate.

That last URL is the correct channel that the browserchannel client should connect on, and the CORS header is right there. Whats the problem? What URL is the browser actually trying to access the server through?

josephg commented 10 years ago

Try configuring your client to use the correct URL, as per the docs:

var s = new BCSocket('http://192.168.1.5:7007/channel', options);
thompsonbill commented 10 years ago

Ok, I changed it to that:

Uncaught TypeError: Object # has no method 'sendMessage' chrome-extension://ffhkkpnppgnfaobgihpdblnhmmbodake/js/content.min.js:1 exports.Doc my.html:30 Could not subscribe: [object Object] share.uncompressed.js:968 Doc._handleSubscribe share.uncompressed.js:968 Object share.uncompressed.js:675

thompsonbill commented 10 years ago

That was from Chrome console, this is what the server is saying:

Listening on http://localhost:7007/ s->c { a: 'init', protocol: 0, id: '528ab1771de523660ceca5d292776555' } c->s { a: 'sub', c: 'users', d: 'seph' } s->c { a: 'sub', error: [Error: failed to connect to [localhost:27017]], c: 'users', d: 'seph' }

josephg commented 10 years ago

Great, so you're connecting through browserchannel. I'm closing this issue.

It looks like you have a different problem - sharejs is trying to use a local mongodb database to store your data, and it can't connect to mongo.

thompsonbill commented 10 years ago

Ah great. mongod won't start anymore. Thanks for your help.

josephg commented 10 years ago

Np.

niftylettuce commented 10 years ago

@thompsonbill @josephg it seems I'm having the same issue, but only in production mode. Can any of you chime in as to how my DB could get created, messages/streams received, but no data being wrote? I can access mongo via CLI and the connection is made from my server.js, however it does not write anything and then results in the following error:

Could not subscribe: [object Object] 

Data is clearly sent on the server log output as { a: 'sub', b: 'test', c: 'blah' }, but it just doesn't write.

This only seems to occur in production mode, so it could be some really wonky issue with my fresh server set up (I've tried a fresh install three times now; using Digital Ocean droplets to no avail). I've got redis AND mongo installed and I even tried to just localhost:27017 for mongo too.

I've followed every other documentation/posting/bit of advice everywhere here and even in the Google Groups too. I tried adding cors: '*' etc. I don't get any CORS errors either, only this DB write issue.

I have a feeling someone might be able to give me some pointer as to why my DB won't write :+1:

Thanks many!

niftylettuce commented 10 years ago

I fixed it, had to use a different DB/server setup for some reason, I think ports were messed up or something. Anyways deployed my app at https://draftling.com/?t=1396977386494#niftylettuce@gmail.com:1396977375401 /cc @thompsonbill @josephg @nornagon thx for awesome project

josephg commented 10 years ago

I'm really glad you fixed whatever the problem was. It would be great to leave a description somewhere of your fix, but this is not the right place for any of this.

Please file issues related to sharejs on the sharejs issue tracker, and please don't hijack existing issue threads to discuss unrelated problems.

niftylettuce commented 10 years ago
niftylettuce commented 10 years ago

@josephg My issue spawned from that one, and then I was led here, that's why I posted here, sorry if it confused you. Thanks and great project.

josephg commented 10 years ago

I understand. Its not your fault - @thompsonbill had additional issues that were unrelated to the original CORS problem we ended up discussing here. I should have insisted on moving the discussion back to the sharejs issue tracker during that discussion.