快递Socket.io 路由parroting/copy/share [英] Express & Socket.io Route parroting/copying/sharing

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

问题描述

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

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.

例如:

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

socket.io 似乎没有这种类型的路由功能.有没有人知道可以帮助解决此问题的库/模块?

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

推荐答案

有几个选项.

如果您不介意使用一些不同的东西,sails 可以让您做到这一点之类的.

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

(更新:sails 现在也使用 express)

(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 路由parroting/copy/share的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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