josephg/node-browserchannel — Issue #2: Cloning of standard headers is not working
Author: nelsonsilva
Created: 2012-02-16 16:21:34+00:00
State: open

I've been trying to get browserchannel to work in cross-origin environments. It should simply be a matter of returning a Access-Control-Allow-Origin: "some origin" to make it work but there seems to be a problem related to the Object.create in https://github.com/josephg/node-browserchannel/blob/master/lib/server.coffee#L839

I added a Access-Control-Allow-Origin key to the standardHeaders along with a simple test:

'Getting proper headers': (test) ->
@get '/channel/test?VER=8&MODE=init', (response) ->
test.equal response.headers['Access-Control-Allow-Origin'.toLowerCase()] , 'http://localhost/'
test.done()

And I noticed that I never got the expected headers and got {"connection":"keep-alive","transfer-encoding":"chunked"} instead

Replacing the Object.create with :

headers = {}
headers[k] = v for k, v of standardHeaders

I Got this working and even ShareJS is working when served through Apache (port 80) using all the JS from http://localhost:8000/ and opening the connection with the proper origin : sharejs.open 'chat', 'json', "http://localhost:8000/channel", (error, doc) =>