当前位置:首页 > 编程笔记 > 正文
已解决

swagger stub https无法访问

来自网友在路上 158858提问 提问时间:2023-10-26 02:40:48阅读次数: 58

最佳答案 问答题库588位专家为你答疑解惑

有个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

);

);

});

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"swagger stub https无法访问":http://eshow365.cn/6-24688-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!