如果你喜歡,以驗證您的節點的應用程序從節點的應用程序中接收安全流量,理查德·阿斯特伯裏有solution on his blog。
tl; dr:IIS充當節點應用程序的代理,並且在請求通過HTTPS提供服務時將「x-arr-ssl」頭添加到請求中。您還可以使用「x-site-deployment-id」標題來驗證您的應用程序當前是否正在以azure運行。中間件結束了,像這樣:
function requireHTTPS(req, res, next) {
var isAzure = req.get('x-site-deployment-id'),
isSsl = req.get('x-arr-ssl');
if (isAzure && !isSsl) {
return res.redirect('https://' + req.get('host') + req.url);
}
next();
}
app.use(requireHTTPS);
當你在它,它添加HSTS是一個好主意,太:
var helmet = require('helmet');
function requireHTTPS(req, res, next) {
var isAzure = req.get('x-site-deployment-id'),
isSsl = req.get('x-arr-ssl');
if (isAzure && !isSsl) {
return res.redirect('https://' + req.get('host') + req.url);
}
next();
}
app.use(requireHTTPS);
app.use(helmet.hsts({
maxAge: 10886400000, // Must be at least 18 weeks to be approved by Google
includeSubdomains: true, // Must be enabled to be approved by Google
preload: true
}));
當然,你可以隨時與web做到這一點串聯.config回答。
這是行得通的,但在瀏覽器上打開app.js文件。有任何想法嗎? – newbie