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 - npm Package Compare versions

Comparing version 0.0.0 to 0.0.1

43

lib/redirectHost.js

@@ -43,23 +43,16 @@ /*!

// Localhost is ignored for redirects
var except = {};
except['127.0.0.1'] = true;
except['localhost'] = true;
// Handle case with a single redirect target domain for all domains
if(typeof options === 'string'){
var acceptable = options;
return function(req, res, next){
var host = req.header('host');
var url = req.url;
if(host === acceptable || host === 'localhost'){
next();
}else{
res.redirect('http://' + acceptable + url);
}
}
except[options] = true;
return createHandler(options, except);
}
// Handle case with a white-list of domains that do not get redirected
var target = options.to;
var except = {};
except[target] = true;
except['localhost'] = true;
var to = options.to;
except[to] = true;

@@ -79,4 +72,18 @@ // Handle single exception specified as a string instead of an array

return createHandler(to, except);
}
/**
* Creates the middleware to handle the redirect
*
* @param {String} to
* @param {Array} except
* @return {Function} middleware function(req, res, next)
* @api private
*/
function createHandler(to, except){
return function(req, res, next){
var host = req.header('host');
var host = (req.header('host') || '').split(':')[0]; // strip port from host
var url = req.url;

@@ -87,5 +94,5 @@

}else{
res.redirect('http://' + target + url);
res.redirect('http://' + to + url);
}
};
}

@@ -5,3 +5,3 @@ {

"description": "Connect middleware for the Express.js framework that allows redirecting multiple domains to a default one",
"version": "0.0.0",
"version": "0.0.1",
"repository": {

@@ -8,0 +8,0 @@ "url": "git@github.com:perropicante/connect-redirecthost.git"

@@ -7,3 +7,3 @@ # Connect Host Redirect

$ npm install node-force-domain
$ npm install connect-redirecthost

@@ -10,0 +10,0 @@ ## Quick Start

@@ -32,3 +32,3 @@ /*!

req.headers['host'] = urlParts.hostname;
req.headers['host'] = urlParts.host;
req.url = (urlParts.pathname || '') + (urlParts.search || '');

@@ -94,6 +94,14 @@

'http://www.example.com'),
'redirect avoided on www.example.com:80': verifyNext(
'http://www.example.com:80'),
'redirect avoided on www.example.com with path and query': verifyNext(
'http://www.example.com//some/path.htm?key1=v1&key2=v2'),
'http://www.example.com/some/path.htm?key1=v1&key2=v2'),
'redirect skipped for localhost': verifyNext(
'http://localhost/')
'http://localhost/'),
'redirect skipped for localhost:3000': verifyNext(
'http://localhost:3000/'),
'redirect skipped for 127.0.0.1': verifyNext(
'http://127.0.0.1/'),
'redirect skipped for 127.0.0.1:3000': verifyNext(
'http://127.0.0.1:3000/')
},

@@ -121,6 +129,14 @@ "Redirect from most subdomains to a single domain, except one" : {

'http://www.example.com'),
'redirect avoided on www.example.com:80': verifyNext(
'http://www.example.com:80'),
'redirect avoided on cdn.example.com': verifyNext(
'http://cdn.example.com'),
'redirect skipped for localhost': verifyNext(
'http://localhost/')
'http://localhost/'),
'redirect skipped for localhost:3000': verifyNext(
'http://localhost:3000/'),
'redirect skipped for 127.0.0.1': verifyNext(
'http://127.0.0.1/'),
'redirect skipped for 127.0.0.1:3000': verifyNext(
'http://127.0.0.1:3000/')
},

@@ -145,2 +161,4 @@ "Redirect from most subdomains to a single domain" : {

'http://www.example.com'),
'redirect avoided on www.example.com:80': verifyNext(
'http://www.example.com:80'),
'redirect avoided on cdn.example.com': verifyNext(

@@ -151,4 +169,10 @@ 'http://cdn.example.com'),

'redirect skipped for localhost': verifyNext(
'http://localhost/')
'http://localhost/'),
'redirect skipped for localhost:3000': verifyNext(
'http://localhost:3000/'),
'redirect skipped for 127.0.0.1': verifyNext(
'http://127.0.0.1/'),
'redirect skipped for 127.0.0.1:3000': verifyNext(
'http://127.0.0.1:3000/')
}
}).export(module);

Sorry, the diff of this file is not supported yet

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