A connect middleware to ensure requests are switched between HTTP and HTTPS properly
surls is a connect middleware to ensure requests are switched between HTTP and HTTPS based on a config.
npm install surls
The first thing you must do is call
configure to specify which URLs should be secured.
You can optionally specify the HTTP and HTTPS port numbers to use.
var surls = require'surls';surlsconfigure'/login' '/resetpassword' httpPort: 1234 httpsPort: 12345 ;
URLs that are to be forced to HTTPS should be specified in the array passed to
You can specify an exact URL match using a string or provide a regex that will be tested against the current request URL.
You can also use an asterisk to indicate that all URLs should be forced to HTTPS.
Only requests to
/account will be forced to HTTPS, all other requests will be forced to HTTP.
/secure9 will be forced to HTTPS, all other requests will be forced to HTTP.
All requests will be forced to HTTPS.
var fs = require'fs';var http = require'http';var https = require'https';var express = require'express';var surls = require'surls';var options =key: fsreadFileSync'server.key'cert: fsreadFileSync'server.crt';surlsconfigure/secure[0-9]/ httpPort: 1234 httpsPort: 12345 ;var app = express;appconfigureappusesurlssecureUrls;;appget'/'ressend'index';;appget'/secure1'ressend'secure 1';;appget'/secure2'ressend'secure 2';;appget'/secure3'ressend'secure 3';;appget'/securez'ressend'secure Z';;httpcreateServerapplisten1234;httpscreateServeroptions applisten12345;