Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/firstandthird/hapi-redirects
Redirect plugin for hapi
https://github.com/firstandthird/hapi-redirects
hapi-plugin hapi-v17
Last synced: 14 days ago
JSON representation
Redirect plugin for hapi
- Host: GitHub
- URL: https://github.com/firstandthird/hapi-redirects
- Owner: firstandthird
- License: mit
- Created: 2014-11-14T17:28:46.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2021-02-19T01:32:19.000Z (almost 4 years ago)
- Last Synced: 2025-01-16T05:56:17.586Z (17 days ago)
- Topics: hapi-plugin, hapi-v17
- Language: JavaScript
- Size: 99.6 KB
- Stars: 1
- Watchers: 6
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
hapi-redirects [![Build Status](https://travis-ci.org/firstandthird/hapi-redirects.svg?branch=master)](https://travis-ci.org/firstandthird/hapi-redirects)
==============Hapi plugin for redirects
## Installation
`npm install --save hapi-redirects`
## Usage
```js
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) {
});
```