[英]Nodejs Fetch API: unable to verify the first certificate
I'm using the fetch API module in my Philips Hue project and when I make a call to the local ip address (my hub) it produces that error in the title.我在我的 Philips Hue 项目中使用 fetch API 模块,当我调用本地 ip 地址(我的集线器)时,它会在标题中产生该错误。
const fetch = require('node-fetch');
const gateway = "192.168.0.12";
const username = "username";
let getLights = function(){
fetch(`https://${gateway}/api/${username}/lights`, {
method: 'GET'
}).then((res) => {
return res.json();
}).then((json) => {
console.log(json);
});
}
module.exports = {getLights};
Any SECURE fix this will eventually go onto the public internet for me to access my lights from anywhere sooo?任何安全修复最终都会将 go 放到公共互联网上,让我可以从任何地方访问我的灯吗?
It seems like you tried to access it using HTTPS.您似乎尝试使用 HTTPS 访问它。 Most likely on your local network it is going to be HTTP
最有可能在您的本地网络上它将是 HTTP
So by changing https://${gateway}/api/${username}/lights
to http://${gateway}/api/${username}/lights
should work.因此,通过将
https://${gateway}/api/${username}/lights
更改为http://${gateway}/api/${username}/lights
应该可以工作。
If you're trying to keep it HTTPS then you will have to install a SSL certificate authority onto your network.如果您想保留它 HTTPS 那么您将必须在您的网络上安装 SSL 证书颁发机构。
These may be useful sources if you're trying to get that done:如果你想完成这些,这些可能是有用的资源:
https://www.freecodecamp.org/news/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec/ https://www.freecodecamp.org/news/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec/
https://letsencrypt.org/docs/certificates-for-localhost/ https://letsencrypt.org/docs/certificates-for-localhost/
To skip the SSL tests, you can use this:要跳过 SSL 测试,您可以使用以下命令:
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.