Socket
Socket
Sign inDemoInstall

attach-ware

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

attach-ware

Middleware with configuration


Version published
Weekly downloads
3.7K
decreased by-21.51%
Maintainers
1
Weekly downloads
 
Created
Source

attach-ware Build Status Coverage Status

Middleware with configuration.

Installation

npm:

npm install attach-ware

attach-ware is also available for bower, component, and duo, and as an AMD, CommonJS, and globals module, uncompressed and compressed.

Usage

x.js:

module.exports = function (ctx, options) {
    if (!options.condition) return;

    return function (req, res, next) {
        res.x = 'hello';
        next();
    };
}

y.js:

module.exports = function (ctx, options) {
    if (!options.condition) return;

    return function (req, res, next) {
        res.y = 'world';
        next();
    };
}

index.js:

var ware = require('attach-ware')(require('ware'));
var x = require('./x.js');
var y = require('./y.js');

var middleware = attachWare()
    .use(x, {'condition': true})
    .use(y, {'condition': false})
    .run({}, {}, function (err, req, res) {
        console.log(res.x); // "hello"
        console.log(res.y); // undefined
    });

API

Note: first create a new constructor (later called AttachWare) by passing ware to the by this module exposed function. This enables ware-like libraries to be used too.

new AttachWare()

Create configurable middleware. Works just like ware().

AttachWare#use(attach, input...)

Invokes attach with either attachWare.context or attachWare, and all input.

If attach returns another function (fn, which can be synchronous, asynchronous, or a generator function), that function is added to the middleware, and will be invoked when run() is invoked like normal middleware.

AttachWare#context

The first argument for attachers. When this is falsey, attachWare itself is used.

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 27 Jul 2015

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc