swagger stub https无法访问

有个app的以前别人写的假服务用http访问可以,但是用https去访问就不行

看官方说schema里面配置一个https就可以了但是对我那个server没有用:

官方参考链接:

API Host and Base Path

后来领导给我发了个这个:

Node.js Express で HTTPSを利用するパターン #Node.js - Qiita

说是需要生成一个证书什么的放在options里面

var options = {

key: fs.readFileSync('../localhost.key'),

cert: fs.readFileSync('../localhost.crt')

};

这里的证书需要生成参考下面的链接里面生成证书的命令,然后放到server的最外层同一级目录下

生成证书命令:

openssl req -x509 -out localhost.crt -keyout localhost.key \
  -newkey rsa:2048 -nodes -sha256 \
  -subj '/CN=localhost' -extensions EXT -config <( \
   printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")

参考链接:localhost 证书 - Let's Encrypt - 免费的SSL/TLS证书

然后在https里面加上这个参数重启服务就可以访问了

https = require("https");

https.createServer(options,app).listen(serverPort_https, function () {

console.log(

"Your server is listening on port %d (https://localhost:%d)",

serverPort_https,

serverPort_https

);

);

});

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值