@polka/redirect 
A response helper for URL redirects; not limited to Polka!
Allows you to easily formulate HTTP redirect responses.
It will set the Location header with the target value, which may be fully-qualified URLs or may be relative to the current URL of the request.
Install
$ npm install --save @polka/redirect
Usage
const polka = require('polka');
const redirect = require('@polka/redirect');
polka()
.get('/foo/bar', (req, res) => {
redirect(res, '../');
redirect(res, './');
redirect(res, 'baz');
redirect(res, '/');
redirect(res, '/bar');
redirect(res, 'https://example.com');
redirect(res, 'https://example.com/foo');
redirect(res, 301, '/');
redirect(res, 301, '/baz');
redirect(res, 301, 'baz?name=bat');
redirect(res, 301, 'https://example.com/foo');
redirect(res, 'back');
redirect(res, 301, 'back');
redirect(res, 'back');
redirect(res, 301, 'back');
});
API
redirect(res, location)
redirect(res, code, location)
res
Type: ServerReponse
The outgoing HTTP response.
code
Type: Number
Default: 302
The statusCode for your response.
location
Type: String
Default: ''
The Location target for your redirect. It may be declared as:
- an absolute path – eg
/, /foo/bar
- a relative path – eg
., .., ./, ../, foo/bar
- a complete URL – eg
https://example.com/foo/bar
- or
"back", which redirects to "/" only when the Referrer is unavailable
Support
Any issues or questions can be sent to the Polka repository.
However, please specify that your inquiry is about @polka/url specifically.
License
MIT © Luke Edwards