【问题标题】:I couldn't setup ssl to my localhost using node js我无法使用节点 js 将 ssl 设置到我的本地主机
【发布时间】:2021-09-11 06:53:04
【问题描述】:

我安装了 OpenSSL,我创建了 cert.pem 和 key.pem,但是我无法使用 node js 和 express js 运行服务器,我认为我的密钥有错误,我该如何解决这个错误,谢谢提前

错误

目录名:

server.js

const express = require('express')
const app = express()
const server = require('https')
const {v4 : uuidv4} = require('uuid')
const fs = require('fs');

app.set('view engine','ejs')
app.use(express.static('public'))

const options = {
   key: fs.readFileSync('key.pem'),
   cert: fs.readFileSync('cert.pem')
};

app.get('/', (req,res) =>{
   res.redirect(`/${uuidv4()}`)

 })
 app.get('/:room' , (req,res) =>{
    res.render('meet' , {roomId : req.params.room})
 })

 server.createServer(options, (req,res) =>{
    console.log('worked')
 }).listen(3030, "192.168.1.20")

【问题讨论】:

    标签: node.js express http https openssl


    【解决方案1】:

    问题是因为 SSL 证书太旧,所以我找到了一个包,它可以工作

    https://dev.to/tingwei628/using-mkcert-in-node-js-ijm

    【讨论】:

      猜你喜欢
      • 2015-04-25
      • 1970-01-01
      • 2018-02-14
      • 2021-08-21
      • 2015-04-20
      • 2013-11-27
      • 1970-01-01
      • 2018-06-02
      • 1970-01-01
      相关资源
      最近更新 更多