express-json-redirects
Middleware that allows you to use JSON to specify redirects in Express
Installation
$ npm install --save @aleph/express-json-redirects
Usage
Your redirects must be a JSON file with an array of objects. The properties of the objects are:
-
route
(Required string) - An Express route, like/someroute
-
target
(Required string) - The route to redirect to, like/target/route
-
status
(Optional integer) - The redirect code you want to return, default302
-
method
(Optional string) - Express method, defaultall
-
qsa
(Optional boolean) - Whether or not to pass along query strings, defaultfalse
This package extends the express
object directly, so you must do a few things
to get it to work. The basic usage alongside Express:
const jsonRedirects = require('express-json-redirects');
const redirects = require('./redirects.json');
const app = express();
jsonRedirects(app);
app.expressJsonRedirects(redirects);
License
MPL-2.0 © Matt Glaser