美文网首页
用 http-server 在本地开启一个 https 服务

用 http-server 在本地开启一个 https 服务

作者: 月下吴刚_c8c7 | 来源:发表于2023-08-10 14:14 被阅读0次

1.先全局安装 http-server

npm i http-server

2.打开当前项目目录在 git bash 中使用以下命令生成一个证书密钥对 key.pem 和 cert.pem,它将有效期约10年(准确地说是3650天)

openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem

3.按步骤输入对应的信息,都可以随意填写


image.png

目录会多出两个文件 cert.pem key.pem

4.通过以下命令就可以运行https服务了

http-server -S -C cert.pem -o  -p 8082  # 默认开启8080

http-server不支持热更新 前端开发可使用live-server代替

相关文章

网友评论

      本文标题:用 http-server 在本地开启一个 https 服务

      本文链接:https://www.haomeiwen.com/subject/xphzpdtx.html