1.0.0 • Published 5 years ago

lazy_redirector v1.0.0

Weekly downloads
2
License
UNLICENSED
Repository
github
Last release
5 years ago

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:

    1. The key is the: {prefix}{domain_to_redirect_from}
    2. The value is a stringified JSON: {domain: domain_to_redirect_to, keepPath: boolean}
    3. The keepPath property preserves the original path after the mapping
    4. 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
VariablePurpose
LAZY_REDIRECTOR_SERVERSet to true to boot the server
PORTThe server port. Defaults to 8000
DEFAULT_ROUTEA domain to redirect traffic if no mapping is found
ERROR_ROUTEA domain to redirect traffic if an error occured
TOKENOptionally set it up. Include it as a URL param to crash the application
MAP_PREFIXThe prefix that all domain-related env variables should start with
FORCE_SSLSet to true to force SSL to all incoming traffic
REDIRECT_JSON_PATHSet 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

    1. env variables
    2. JSON file
  • Add the {name}.redirector middleware to the express chain

1.0.0

5 years ago