JSPM

deviate

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 31777
  • Score
    100M100P100Q136831F
  • License MIT

Redirecting middlware for express or node.js

Package Exports

  • deviate

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (deviate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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

Build Status Dependency Status

Usage

var deviate = require('deviate');

var express = require('express');
var app = express();

app.get('/random', deviate(function (req) { return '/post/' + Math.random(); }));

app.get('/page/:no/next', deviate('/page/[Number:no + 1]'));
app.get('/page/:no/prev', deviate('/page/[Number:no - 1]'));

app.get('/:number', deviate(301, '/post/:number'));

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