Secure express.js 3 申请
使用 express.js 进行安全连接的配置(从版本 3 开始):
var fs = require('fs');
var http = require('http');
var https = require('https');
var privateKey = fs.readFileSync('sslcert/server.key', 'utf8');
var certificate = fs.readFileSync('sslcert/server.crt', 'utf8');
// Define your key and cert
var credentials = {key: privateKey, cert: certificate};
var express = require('express');
var app = express();
// your express configuration here
var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);
// Using port 8080 for http and 8443 for https
httpServer.listen(8080);
httpsServer.listen(8443);
通过这种方式,你可以向本机 http / https 服务器提供快速中间件
如果你希望应用程序在低于 1024 的端口上运行,则需要使用 sudo 命令(不推荐)或使用反向代理(例如 nginx,haproxy)。