我正在创建一个简单的HTTP-> HTTPS转发服务器,如下所述: Heroku HTTPS redirect
我很肯定我必须忽略一些简单的东西,但即使日志将我的DEVMODE打印为false,它也不会在* route处理程序中捕获它。它超越了这条线。
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);
我确信我必须忽视一些非常简单的事情。知道为什么process.env.DEVMODE if语句中的代码没有被调用吗?
非常感谢!
答案 0 :(得分:1)
环境变量是字符串,所以试试这个:
if (process.env.DEVMODE == "false") {
...
}