lazy_redirector
v1.0.0
Published
Lazy NodeJS Redirector
Downloads
3
Readme
Redirector
Lazy NodeJS Redirect
Don't bother if you can properly set up NGINX.
The premise here is to redirect traffic from URL A to URL B.
Declare domains
Environment Variables
Set the MAP_PREFIX env variable. All your entries should be prefixed.
Add multiple variables where:
The key is the: {prefix}{domain_to_redirect_from}
The value is a stringified JSON: {domain: domain_to_redirect_to, keepPath: boolean}
The keepPath property preserves the original path after the mapping
For example
prefix = RD_ {prefix}{domain_to_redirect_from} = '{"domain":"{domain_to_redirect_to}","keepPath":true}'
JSON
- Set the REDIRECT_JSON_PATH env variable to the JSON file path
- The path is read like so:
process.cwd() + `/` + process.env.REDIRECT_JSON_PATH
- Check here
How to
Standalone server
- Configure these env variables
|Variable|Purpose| |--------|-------| |LAZY_REDIRECTOR_SERVER|Set to true to boot the server| |PORT|The server port. Defaults to 8000| |DEFAULT_ROUTE|A domain to redirect traffic if no mapping is found| |ERROR_ROUTE|A domain to redirect traffic if an error occured| |TOKEN|Optionally set it up. Include it as a URL param to crash the application| |MAP_PREFIX|The prefix that all domain-related env variables should start with| |FORCE_SSL|Set to true to force SSL to all incoming traffic| |REDIRECT_JSON_PATH|Set the filepath to read the JSON file|
Run in DEV
Set the enc variable ENVIRONMENT to "SERVER_DEV", and node server/index.js
Module
Require the module
Use the {name}.map function to parse the domain list from
- env variables
- JSON file
Add the {name}.redirector middleware to the express chain