Reputation: 5539
I'm creating a simple HTTP->HTTPS forwarding server as talked about here: Heroku HTTPS redirect
I'm positive I must be overlooking something simple, but even though the log is printing my DEVMODE as false, it's not catching it in the * route handler. It goes right past the line.
var port = process.env.PORT || 1337;
var express = require('express');
var app = express();
var path = require('path');
var fs = require('fs');
console.log("DEVMODE= " + process.env.DEVMODE); //outputs DEVMODE=false
app.get('*',function(req,res,next){
if (process.env.DEVMODE == false){
//-----NOTHING REACHES THIS POINT though it just said process.env.DEVMODE = false
if( req.headers['x-forwarded-proto'] != 'https' )
res.redirect('https://mydomain.com'+req.url)
else
next() /* Continue to other routes if we're not redirecting */
} else {
//-----Goes straight to here.
next();
}
})
app.use(express.static(__dirname));
app.listen(port);
I'm sure I must be overlooking something very simple. Any idea why the code inside the process.env.DEVMODE if statement is not getting called?
Many thanks!
Upvotes: 1
Views: 72
Reputation: 203359
Environment variables are strings, so try this:
if (process.env.DEVMODE == "false") {
...
}
Upvotes: 1