Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

68 lines (53 sloc) 1.191 kB

middler

A trivial middleware runner

Idea

middler is a lightweight middleware runner for Node.js, packing express-like routing and full connect/union compatibility. Best of all, the code is dead simple and dependency-free.

Enjoy!

Install

$ npm install middler

Basic usage

var middler = require('middler')
  , server = require('http').createServer()
  , buffet = require('buffet')('./public')

middler(server)
  .add(buffet)
  .add(function(req, res, next) {
    // ... do some stuff
    next();
  })
  .add(buffet.notFound);

Routing

middler(server)
  .get('/robots.txt', function (req, res, next) {
    res.end('humans only!');
  })
  .post('/posts/:id', function (req, res, next) {
    // req.params.id available
  });

union compatibility

middler(server)
  .add(function () {
    // this.req
    // this.res
    this.res.emit('next');
  });

License

MIT

Jump to Line
Something went wrong with that request. Please try again.