Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

SockJS-node doesn't work with express 3.0 #78

Closed
majek opened this Issue Jun 28, 2012 · 5 comments

Comments

Projects
None yet
3 participants
Owner

majek commented Jun 28, 2012

@squaremo reported that sockjs doesn't work with express 3.0, it does work with 2.5 though.

yes it seems that express 3.0 overwrite sockjs transport path .
take the echo examlple using sockjs prefix "/echo" .
with express 3.0, paths /echo and /echo/info return : 404 not found.

I managed to get it working.
express 3.0 made a breaking change.
here are instructions to move from express 2.x to 3.x

given the following code with express 2.x :

var sockjs  = require('sockjs');
var express = require('express');
...
/* sockjs stuff */
...
var app = express.createServer();

sockjs_server.installHandlers(app , {prefix:'/echo'});

app.configure(....)

app.listen(8080);

to make it compatible with express 3.x you should do :

var sockjs  = require('sockjs');
var express = require('express');
...
/* sockjs stuff */
...

var app = express(); /* express.createServer will not work here */
var server = require('http').createServer(app); /*create a nodejs http server */

sockjs_server.installHandlers(server, {prefix:'/echo'}); /*use http server instead of express app */

app.configure(....)

server.listen(8080); /*listen on http server instead of express app */

@majek majek closed this in ef57a99 Aug 15, 2012

Owner

majek commented Aug 15, 2012

This was very helpful. I prepared a separate example specially for express 3.x, thanks!

This isn't ideal - now sessions won't play nicely between normal HTTP requests and SockJS connections?

Owner

majek commented Nov 29, 2012

Sessions are usually based on cookies. SockJS doesn't do cookies due to the cross-domain nature. You need to authorize sockjs sessions manually. The recommended way is to pass a token / hmac / cookie as a first message over sockjs connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment