@rowanmanning/response-redirect-middleware
v4.2.1
Published
A small convenience utility to generate Express middleware which redirects a request
Downloads
8
Maintainers
Readme
@rowanmanning/response-redirect-middleware
A small convenience utility to generate Express middleware which redirects a request.
app.get('/', redirect('/login'));
Table of Contents
Requirements
This library requires the following to run:
- Node.js 18+
Usage
Install with npm:
npm install @rowanmanning/response-redirect-middleware
Load the library into your code with a require
call:
const redirect = require('@rowanmanning/response-redirect-middleware');
Use it to generate middleware to redirect a view:
const app = express();
app.get('/', redirect('/login'));
The following are equivalent:
app.get('/', redirect('/login'));
app.get('/', (request, response) => response.redirect('/login'));
app.get('/posts', redirect(301, '/blog'));
app.get('/posts', (request, response) => response.redirect(301, '/blog'));
If you need to pass dynamic information into the redirect, don't use this middleware.
Contributing
The contributing guide is available here. All contributors must follow this library's code of conduct.
License
Licensed under the MIT license. Copyright © 2020, Rowan Manning