多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# https # 使用 Express 搭建 HTTPS 服务 ``` var fs = require('fs'); var http = require('http'); var https = require('https'); var path = require('path'); var privateKey = fs.readFileSync(path.join(__dirname, 'ca', 'server.key'), 'utf8'); var certificate = fs.readFileSync(path.join(__dirname, 'ca', 'server.crt'), 'utf8'); var credentials = {key: privateKey, cert: certificate}; var express = require('express'); var app = express(); // your express configuration here app.get('/a', (req, res) => { res.send('https'); }) var httpServer = http.createServer(app); // 创建应用 var httpsServer = https.createServer(credentials, app); // 创建应用 httpServer.listen(8080); httpsServer.listen(8443); ```