express.io-middleware
This Express.io extension adds middleware and multiroute functionality to app.io. It also adds app.io.event
and app.io.namespace properties, which contains signal name and namespace (before ':' part) respectively.
Tested with express.io 1.1.x.
Installation:
$ npm install express.io-middleware
Example:
app.http().io();
require('express.io-middleware')(app);
app.io.use(function (req, next) {
console.log(req.data);
if (!req.data) {
req.respond(':-(');
} else {
next();
}
});
app.io.use(/.+:save/, function (req, next) {
if (typeof req.data != 'object') {
req.io.emit('invalid data received');
} else {
next();
}
});
app.io.route('entity', {
save: function (req, next) {}
});
app.io.route('entity:save', endpoint);
Note that all middlewares should be declared strongly before declaration of routes, for which it should be applied.