UNPKG

nodal

Version:

An API Server and Framework for node.js

27 lines (16 loc) 473 B
'use strict'; const Nodal = require('nodal'); /* Forces HTTPS */ class ForceHTTPSMiddleware { exec(controller, callback) { let headers = controller._requestHeaders; let host = headers.host || ''; if (headers.hasOwnProperty('x-forwarded-proto') && headers['x-forwarded-proto'] !== 'https') { controller.redirect(`https://${host}${controller._path}`); return; } callback(null); } } module.exports = ForceHTTPSMiddleware;