4.0.1 • Published 5 years ago
hapi-redirect v4.0.1
Hapi redirect
A small library for redirecting requests based on http/s status code to another endpoint
Installation
npm install --save hapi-redirect
Usage
'use strict'
const Hapi = require( 'hapi' );
const server = new Hapi.Server( { port: 3000 } );
server.register( {
plugin: require( 'hapi-redirect' ),
options: {
actions: [{
status_code: 401,
redirect: (url)=>{ return {url:'/login'}
}]
}
}, ( err ) => {
// Oh no!
} );
API
hapi-redirect
hapi-redirect.plugin
options
Object with the following keysactions
{array} List with redirect actionsstatus_code
{string} Request status code to redirect e.g. 401 - unauthorizedredirect(url)
{function} Function that should return{ url: ..., [host:...]}
url
Current url to be redirected from if redirect should be done or null if not
Kind: static property of hapi-redirect
Tests
npm run-script test-locally
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.