node.jshttpfetchphilips-hue

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.

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?


Solution

  • It seems like you tried to access it using HTTPS. Most likely on your local network it is going to be HTTP

    So by changing https://${gateway}/api/${username}/lights to http://${gateway}/api/${username}/lights should work.

    If you're trying to keep it HTTPS then you will have to install a SSL certificate authority onto your network.
    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://letsencrypt.org/docs/certificates-for-localhost/