hapi-redirect

4.0.1 • Public • Published

Build Status Coverage Status

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 keys
    • actions {array} List with redirect actions
      • status_code {string} Request status code to redirect e.g. 401 - unauthorized
      • redirect(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.

Package Sidebar

Install

npm i hapi-redirect

Weekly Downloads

8

Version

4.0.1

License

MIT

Unpacked Size

16.9 kB

Total Files

10

Last publish

Collaborators

  • mikaellindahl