Socket
Book a DemoInstallSign in
Socket

express.io-middleware

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express.io-middleware

This Express.io extension adds middleware and multiroute functionality to app.io

0.9.4
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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); // first of all, you should patch express.io app after calling app.io();

/**
* @param {Object} req Is express.io request object
* @param {Function} next Is a pointer to the next handler in chain.
*/
app.io.use(function (req, next) {
  console.log(req.data);
  if (!req.data) {
    req.respond(':-(');
  } else {
    next();
  }
});

/**
* You may use regular expressions to bind middleware execution only for specified signals.
*/
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) {}
});

/**
* Also, you may build chain of signals handlers.
*/
app.io.route('entity:save', endpoint);

Note that all middlewares should be declared strongly before declaration of routes, for which it should be applied.

Keywords

express.io

FAQs

Package last updated on 30 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.