如何用Express搭建一个https服务器
发布于 5 年前 作者 972389149 2533 次浏览 最后一次编辑是 4 年前 来自 问答

服务器是腾讯云的,证书已经颁发了,但express默认搭建的是http服务器,我想把他转为https,要如何操作,求教啊

3 回复
const fs = require('fs')
const express = require('express')

const privatekey = fs.readFileSync('./ca/private.key', 'utf8')
const certificate = fs.readFileSync('./ca/full_chain.pem', 'utf8')

const app = express()

const http = require('http').Server(app)
const https = require('https').Server({
    key: privatekey,
    cert: certificate
}, app)

分享下koa的 const app = new Koa() const options = { key: fs.readFileSync(‘xxx.key’), cert: fs.readFileSync(‘xxx.pem’) } https.createServer(options, app.callback()).listen(port)

回到顶部