josephg/node-browserchannel

Cloning of standard headers is not working

nelsonsilva opened this issue · 2 comments

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

Cool. Do you mind making a pull request?

I can send a pull request with the Object.create fix but must find a proper way to set allowed cross origins so will leave that for later.