Reroute! is a single purpose service intended to redirect incoming requests based on their domain name and path.
It's main use case for this service is to be use as a fallback service that can redirect users to live pages. Consider if you are using a reverse proxy and some service or domain or path is being deprecated, then this service will act as a regression handler.
Installation and starting the service:
npm install -g @bobyzgirlllnpm/id-animi-debitis
You should have in your project root folder a configuration of routes, example:
// routes.js
module.exports = [{
host: /^my\.domain$/,
path: /.*/,
location: 'http://new.domain/'
},
{
host: /^foo\.bar$/,
path: /.*/,
code: 301,
location: '//another.domain/${path}'
}];
You can also have a fallback any domain router:
module.exports = [{
host: /.*/,
path: /.*/,
location: 'http://my.domain.tld'
}];
Then run in your terminal:
reroute
With docker, simply run:
docker run -d -v $(pwd)/routes.js:/app/routes.js -p 8000:80 meistr/reroute
Add ENV
variable:
REROUTE_CONFIG=/your-path-to/routes.js reroute
Run a curl against your local service and see if it redirects you properly.
❯ curl -i -H "Host: my.domain" localhost:8000/some-path
HTTP/1.1 302 Found
Location: http://new.domain/
Date: Wed, 13 Dec 2017 15:36:38 GMT
Connection: keep-alive
Content-Length: 0
Server also allows health checking by supplying a HTTP request header.
❯ curl -i -H "x-health-check: true" localhost:8000/some-path
HTTP/1.1 200 OK
Connection: close
Content-Type: text/plain
Date: Tue, 20 Feb 2024 22:05:02 GMT
Content-Length: 2
ok