josephg/node-browserchannel

BrowserChannel CORS not working with ShareJS 0.7

thompsonbill opened this issue · 15 comments

Continued from this issue: josephg/ShareJS#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

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

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

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?

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);

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

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' }

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.

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

Np.

@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 👍

Thanks many!

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

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.

@josephg Why did you post this then?... josephg/ShareJS#293 (comment)

@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.

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.