Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

connect-redirecthost

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-redirecthost

Connect middleware for the Express.js framework that allows redirecting multiple domains to a default one

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Connect Host Redirect

connect-redirecthost is middleware for the Express.js framework that allows redirecting multiple domains to a default one.

Installation

$ npm install connect-redirecthost

Quick Start

Using connect-redirecthost is easy. Register it within Express.js as middleware by adding the following line into your app.js file before most calls to app.use(...):

app.use(require('connect-redirecthost').redirectHost('www.example.com'));

Localhost is always excluded to make local development easier.

Exceptions

Redirect exceptions are supported. If, for example, your site uses a CDN on a separate domain, you can create an exception for that domain

app.use(require('connect-redirecthost').redirectHost({
 to: 'www.example.com',       // all requests not on www.example.com will be redirected to www.example.com
 except: 'cdn.example.com'    // except for those to cdn.example.com
}));

You can also specify multiple exceptions using an array.

app.use(require('connect-redirecthost').redirectHost({
 to: 'www.example.com',
 except: ['cdn.example.com', 'origin.example.com']
}));

Path handling

By default, the root-relative path is preserved during the redirect. Should the root relative path need to be modified reset, the following options can be used, where the path will be set to the associated domain's value

    to: 'www.example.com',
    changePath: {'www.example.ca': '/ca', 'www.example.us': '/us'}
}));```

You can also specify a function to determine the new path;

```app.use(require('connect-redirecthost').redirectHost({
    to: 'www.example.com',
    changePath: {
     'www.example.ca': function(host, url){return '/ca' + url;},
     'www.example.us': function(host, url){return '/us' + url;}
    }
}));```


## License

View the LICENSE file.


FAQs

Package last updated on 08 Feb 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc