@meister/reroute

1.4.0 • Public • Published

Reroute!

Build Status Known Vulnerabilities

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

Installation and starting the service:

npm install -g @meister/reroute

Configure routes

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'
}];

Run server

Then run in your terminal:

reroute

Running in Docker

With docker, simply run:

docker run -d -v $(pwd)/routes.js:/app/routes.js -p 8000:80 meistr/reroute

Specifying custom routes path

Add ENV variable:

REROUTE_CONFIG=/your-path-to/routes.js reroute

Test the running server

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

Health Check

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

Package Sidebar

Install

npm i @meister/reroute

Weekly Downloads

3

Version

1.4.0

License

MIT

Unpacked Size

21.6 kB

Total Files

21

Last publish

Collaborators

  • meister