Node.js express 如何启用 https SSL?
1 个回答
直接看代码吧:
const fs = require('fs');
const https = require('https');
const express = require('express');
const app = express();
app.get('/', function (req, res) {
res.send('Code Player Hello World!');
});
// 读取SSL证书文件
let key = fs.readFileSync('ssl/server.key', 'utf8'),
cert = fs.readFileSync('ssl/server.pem', 'utf8');
let credentials = { key, cert };
let server = https.createServer(credentials, app);
server.listen(443, '0.0.0.0');