Casey Flynn
Casey Flynn

Reputation: 14038

Express & Socket.io Route parroting/copying/sharing

I'm working with expressjs and socket.io in nodejs. I'm looking into assign identical route handlers to requests made in either HTTP or via websockets/socket.io.

For instance:

var responder = function(req, res){
  req.params //<-- {id: 'something...'}
}
app.get('/foo/:id', responder);
io.on('/foo/:id', responder);

socket.io doesn't appear to have this type of routing functionality. Does anyone know of a library/module to help with this?

Upvotes: 1

Views: 1688

Answers (1)

Benjamin Gruenbaum
Benjamin Gruenbaum

Reputation: 276306

There are several options.

  • If you'd like to keep using , check out express.io.

  • If you don't mind using something a bit different, sails lets you do this sort of thing as well.

(Update: sails now uses express too)

Both have been used in production successfully.

Note that routing is also pretty simple to implement on your own. If you check out how express do it I'm sure you'll be able to figure out a slim implementation that would match you needs.

Good luck! Let me know what you ended up using and how it worked for you.

Upvotes: 3

Related Questions