Nodejs Fetch API:无法验证第一个证书

4
我在我的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};

有没有安全的解决方案可以让我从任何地方访问我的灯光,因为这个解决方案最终会放到公共互联网上?

2个回答

9
为跳过SSL测试,您可以使用以下代码:
``` process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0; ```

有没有可能在任何地方添加SSL证书,而不是使所有内容都不安全? - undefined

1
似乎您尝试使用HTTPS访问它。在您的本地网络上,最有可能是HTTP。因此,将https://${gateway}/api/${username}/lights更改为http://${gateway}/api/${username}/lights应该可以解决问题。如果您想保持HTTPS,则必须在您的网络中安装SSL证书颁发机构。如果您正在尝试完成此操作,则以下资源可能会有所帮助:

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/


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接