A Node.js server to redirect a public hostname to another including the full URL and the port
Examples of this server functionality
- redirect
source-hostname.com
TOdestination-hostname.com
- redirect
source-hostname.com/some-url-goes-here
TOdestination-hostname.com/some-url-goes-here
- redirect
source-hostname.com/programs?withQuery=true
TOdestination-hostname.com/programs?withQuery=true
- redirect
source-hostname.com/programs#withHash
TOdestination-hostname.com/programs#withHash
- redirect
source-hostname.com:5050
TOdestination-hostname.com:5050
- node.js
>=16.13.2
- yarn
>= 1.22.15
git clone https://github.com/amjedomar/hostname-redirector
- to install dependencies run:
yarn
- to run the development server run:
yarn dev
- to run the production server run:
yarn build && yarn start
- to run the production server using pm2 run:
yarn build && yarn start:pm2
To tell the server the hostnames that will be redirected, set for each one of them an environment variable that follow these two rules
- First: its key (name) must starts with
REDIRECT_HOSTNAME_
- Second: its value must follow this format
source-hostname.com -> destination-hostname.com
Notice that:
- you must NOT include a protocol in both source and destination hostnames
- you must NOT end hostnames with slash
/
- you must NOT include a port
- you must spread the source and destination hostnames with
->
(and two spaces before and after->
must be included)
Redirection Environment Variables Examples
REDIRECT_HOSTNAME_WWW_Example_COM='www.example.com -> example.com'
REDIRECT_HOSTNAME_2='my-tool.org -> my-tool.js.org'
Note: the server should have the access of the hostnames that will be redirected otherwise the server can't redirect them.
Also Note: you can also setup these environment variables by creating
.env
file in the root directory of this project and put them on it