var conf = require('../conf');

/**
 * Check whether Transport Layer Security (TLS) is forced in the config. If
 * forceTLS option is set to true, redirect all unsecured HTTP traffic to HTTPS.
 **/
module.exports = function forceTLS(req, res, next) {
  if (conf.forceTLS && conf.securePort && !req.secure) {
    var redirectPath = ['https://', req.hostname];

    if (conf.securePort != 443) {
      redirectPath.push(':');
      redirectPath.push(conf.securePort);
    }

    redirectPath.push(req.url);

    return res.redirect(301, redirectPath.join(''));
  }
  next();
}

var conf = require('../../conf');

/**
 * Check whether Transport Layer Security (TLS) is forced in the config. If
 * forceTLS option is set to true, redirect all unsecured HTTP traffic to HTTPS.
 **/
module.exports = function forceTLS(req, res, next) {
  if (conf.forceTLS && conf.securePort && !req.secure) {
    return res.redirect(['https://', req.get('Host'), req.url].join(''));
  }
  next();
}

--- 
+++ 
@@ -1,4 +1,4 @@
-var conf = require('../../conf');
+var conf = require('../conf');
 
 /**
  * Check whether Transport Layer Security (TLS) is forced in the config. If
@@ -6,7 +6,16 @@
  **/
 module.exports = function forceTLS(req, res, next) {
   if (conf.forceTLS && conf.securePort && !req.secure) {
-    return res.redirect(['https://', req.get('Host'), req.url].join(''));
+    var redirectPath = ['https://', req.hostname];
+
+    if (conf.securePort != 443) {
+      redirectPath.push(':');
+      redirectPath.push(conf.securePort);
+    }
+
+    redirectPath.push(req.url);
+
+    return res.redirect(301, redirectPath.join(''));
   }
   next();
 }
Add custom port to the redirect path
