快递Socket.io路由示范/复制/共享 [英] Express & Socket.io Route parroting/copying/sharing

查看:130
本文介绍了快递Socket.io路由示范/复制/共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用在nodejs中的expressjs和socket.io。我正在考虑为HTTP或通过websockets / socket.io发出的请求分配相同的路由处理程序。



例如:

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

socket.io似乎没有这种类型的路由功能。有没有人知道一个图书馆/模块来帮助这个?

解决方案

有几个选项。




  • 如果你想继续使用 express ,查看 express.io


  • 如果你不介意使用一些不同的东西, sails 可以让你做这样的事情。




更新:sails现在也使用express)



两者都已经在生产中成功使用。



请注意,路由自身也很简单实现。如果您查看如何表达这一点我相信你会能够找出符合您需求的细微实施方案。



祝你好运!让我知道你最终使用了什么,以及它如何为你工作。


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?

解决方案

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.

这篇关于快递Socket.io路由示范/复制/共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆