New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

https-redirect-server

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

https-redirect-server

A node module to redirect requests from a non-secure port to a secure port.

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

https-redirect-server

A node module to redirect requests from a non-secure port to a secure port.

what is https-redirect-server?

This is a node module that currently supports two ways of redirecting from a non-secure connection to a secure connection.

If you want to force all traffic to come to your site via a secure connection, a small, lightweight http server can be run to redirect all traffic to https and a secure port.

If you want to force specific routes to use a secure connection, a middleware function can be used with express to redirect insecure traffic to https and a secure port.

Using the redirect server

This will start a server running on an insecure port that will redirect all traffic. Here is an example of how to use it alongside an express server:

var express       = require('express');
var https         = require('https');
var port          = process.env.PORT || 8080;
var securePort    = process.env.PORT || 8443;
var httpsRedirect = require('https-redirect-server');

// configure application and routes
app.get('/', function(req, res, next) {
  // ...
});

app.get('/login', function(req, res, next) {
  // ...
});

// set ssl options
var ssl_options = {
  key: fs.readFileSync(__dirname + '/website.key'),
  cert: fs.readFileSync(__dirname + '/website.cert')
};

// start servers
httpsRedirect(port, securePort).server(); // will redirect anything to receives

https.createServer(ssl_options, app).listen(securePort);

Using the forceSecure middleware

This will only redirect routes that you specify to use the middleware. Here is an example of how to redirect traffic that is going to the login page of an express server:

var express       = require('express');
var http          = require('http');
var https         = require('https');
var port          = process.env.PORT || 8080;
var securePort    = process.env.PORT || 8443;
var httpsRedirect = require('https-redirect-server');

var forceSecure   = httpsRedirect(port, securePort);

// configure application and routes
app.get('/', function(req, res, next) { 
  // ...
});

// add middleware to redirect request if it is not secure
app.get('/login', forceSecure, function(req, res, next) {
  // ...
});

// set ssl options
var ssl_options = {
  key: fs.readFileSync(__dirname + '/website.key'),
  cert: fs.readFileSync(__dirname + '/website.cert')
};

// start servers, one for insecure and one for secure
http.createServer(app).listen(port); 

https.createServer(ssl_options, app).listen(securePort);

Keywords

https redirect server

FAQs

Package last updated on 14 Aug 2014

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