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

时间:2020-07-05 20:57:46

标签: node.js http fetch philips-hue

我在Philips Hue项目中使用了访存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};

任何SECURE修复程序最终都会进入公共互联网,让我可以从任何地方访问灯吗?

2 个答案:

答案 0 :(得分: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/

答案 1 :(得分:0)

要跳过 SSL 测试,您可以使用:

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;