node express将请求重定向为https

项目开发时,由于服务器只接受https请求,所以在生产环境时,要把所有http请求全都重定向为https,具体操作是在app.js文件里加入以下代码:

var express = require('express');
var toHttps = require('express-to-https').basic;
if(clusterUtility.API.clusterType == "release"){
    //判断只在生产环境使用此插件
    app.use(toHttps);
}
posted @ 2018-01-05 09:27  罗知晏  阅读(1718)  评论(0编辑  收藏  举报