Hairgami_Master
Hairgami_Master

Reputation: 5539

Any idea why this simple ExpressJS app is not picking up Heroku Env Vars?

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

Answers (1)

robertklep
robertklep

Reputation: 203359

Environment variables are strings, so try this:

if (process.env.DEVMODE == "false") {
  ...
}

Upvotes: 1

Related Questions