deviate

Redirecting middlware for express or node.js

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
deviate
811.0.011 years ago11 years agoMinified + gzip package size for deviate in KB

Readme

deviate
Redirecting middlware for express or node.js
  • supports ert syntax
  • supports a function that takes req and returns the path
  • uses res.redirect if it's used with express
  • falls back to manually writing the header elsewhere

Usage

```js var deviate = require('deviate'); var express = require('express'); var app = express(); app.get('/:number', deviate(301, '/post/:number')); app.get('/random', deviate(function (req) { return '/post/' + Math.random(); })); app.get('/page/:no/next', deviate('/page/1 + :no')); app.get('/page/:no/next', deviate('/page/-1 + :no')); app.listen(3000); ```

API

deviate([status,] path) Deviate takes an optional status (which defaults to 302) and a path or function. It then returns a middleware function which takes req and res and redirects res to the path.

License

MIT