Following another SO question , the last thing I'm trying to do (see ligatures.net ):
self.ipaddress = process.env.OPENSHIFT_NODEJS_IP; self.port = process.env.OPENSHIFT_NODEJS_PORT || 443; if (typeof self.ipaddress === "undefined") { self.ipaddress = "127.0.0.1"; }; ... self.app = express(); // 4.8.7 ... // Trusting Openshift proxy self.app.enable('trust proxy'); // Http -> Https redirection middleware self.app.use(function (req, res, next) { if ( !req.secure() ) { var tmp = 'https://' + process.env["DOMAIN_NAME"] + req.originalUrl; console.log("Redirect to: " + tmp); res.redirect(tmp); } else { next(); } }); ... // Creating a http server https.createServer(self.app).listen(self.port, self.ipaddress, function(err) { if (err) { console.log("Node server error: " + err.toString()); } else { console.log('%s: Node server started on %s:%d ...', Date(Date.now() ), self.ipaddress, self.port); } });
In Openshift magazines, I get:
The 'secure' property of object # is not a function
This is the line: if ( !req.secure() ) {
Certificates are uploaded to the console. The application runs successfully on port 8080.
Why am I receiving this message and how do I create a secure htp 4.0 Express application in OpenShift? Does anyone have a transaction code to share? Thanks!
UPDATE
I updated the redirect as follows:
// Http -> Https redirection middleware self.app.use(function (req, res, next) { if ( req.headers['x-forwarded-proto'] === 'http' ) { var tmp = 'https://' + req.headers.host + req.originalUrl; console.log("SERVER redirect to: " + tmp); res.redirect(tmp); } else { var pt = req.protocol || ""; var ho = req.headers.host || ""; var ur = req.originalUrl || ""; console.log("\nProtocol: " + pt + "\nHost : " + ho + "\nUrl : " + ur); var tmp = req.protocol + '://' + req.headers.host + req.originalUrl; console.log("SERVER no redirect: " + tmp); next(); }
I see a couple of commands from the console:
SERVER no redirect: http://undefined/ Protocol: http Host : Url : /
and my application is still not working. This seems like a mistake.
I discovered the problem: https://bugzilla.redhat.com/show_bug.cgi?id=1138137
I am also for Cloudflare, which may be part of the problem.