7.1.2 • Published 3 years ago

hapi-redirects v7.1.2

Weekly downloads
41
License
MIT
Repository
github
Last release
3 years ago

hapi-redirects Build Status

Hapi plugin for redirects

Installation

npm install --save hapi-redirects

Usage

server.register([
  {
    plugin: require('hapi-redirects'), options: {
      log: true,
      log404: true,
      // can match any valid hapi route specifier including route params and redirect to the specified value:
      redirects: {
        "/shortlink": "/a/much/longer/path?search=longer",
        '/post/(.*)/': '/cats',
        '/*': '/newtest',
        '/cats302': {
          destination: '/cats',
          statusCode: 302 // can overload the type of HTTP redirect
        },
        "/cats/cute": "/search?animal=cat&type=cute"
      },
      vhosts: {
        'cats.com': {
          '/cats-also': '/cats',
        }
      },
      // can be passed a function that dynamically generates new route
      // redirections every time an HTTP request is handled:
      getRedirects(pluginOptions, callback) {
        // the first parameter contains the plugin options:
        if (pluginOptions.log) {
          server.log(['redirect', 'cats'], 'cats');
        }
        // callback takes any error as the first param and a list of route redirections as the second:
        return callback(null, [
          {
            // this will HTTP 302 redirect every incoming request to '/dynamic-cats' to a different destination:
            '/dynamic-cats': {
              destination: '/cats/' + Math.random(),  
              statusCode: 302
            },
          }
        ]);
      }
    }
  }}
], function(err) {
});
7.1.2

3 years ago

7.1.0

5 years ago

7.0.3

5 years ago

7.0.2

5 years ago

7.0.1

5 years ago

7.0.0

6 years ago

6.2.3

6 years ago

6.2.2

6 years ago

6.2.1

6 years ago

6.2.0

6 years ago

6.1.0

6 years ago

6.0.0

6 years ago

5.0.0

7 years ago

4.2.0

7 years ago

4.1.0

7 years ago

4.0.0

8 years ago

3.0.0

8 years ago

2.0.0

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.1.0

9 years ago