Skip to content

express-http-to-https is a node.js package for providing an Express middleware that redirects the client to HTTPS if they attempt to connect over HTTP.

License

Notifications You must be signed in to change notification settings

SegFaultx64/express-http-to-https

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-http-to-https

express-http-to-https is a node.js package for providing an Express middleware that redirects the client to HTTPS if they attempt to connect over HTTP.

Installation

$ npm install --save express-http-to-https

Usage

app.use(redirectToHTTPS(ignoreHosts, ignoreRoutes));

Configuration Options

  • ignoreHosts: An array of strings of the hostnames on which to not enable the redirect. note: you must include the port here, for example [/localhost:8080/].
  • ignoreRoutes: An array of strings of the routes on which not to enable the redirect.
  • redirectCode: The HTTP status code to return when redirecting. Defaults to 302 "found" can be any status code

Example

var express = require('express');
var app = express();

var redirectToHTTPS = require('express-http-to-https').redirectToHTTPS

// Don't redirect if the hostname is `localhost:port` or the route is `/insecure`
app.use(redirectToHTTPS([/localhost:(\d{4})/], [/\/insecure/], 301));

app.get('/', function (req, res) {
  res.send('Hello World!');
});

app.get('/insecure', function (req, res) {
  res.send('Dangerous!');
});

app.listen(3000, function () {
  console.log('Example app listening on port 3000!');
});

app.listen(8080, function () {
  console.log('Example app listening on port 8080 insecurely!');
});

JavaScript Style Guide

License

MIT License

Author

Max Walker (max@maxwalker.me)

Contributors

Aleksander Szmigiel

About

express-http-to-https is a node.js package for providing an Express middleware that redirects the client to HTTPS if they attempt to connect over HTTP.

Resources

License

Stars

Watchers

Forks

Packages

No packages published