Goal
Ensure security in my request message.
Environment:
Library: Version
node-fetch : 2.6.0
https : natively implemented in node, it seems
node : 12.15.0
Device : Version
- Google home nest mini : 2nd generation
Issue
I get a "Failed to fetch" error when I do get request on an api served with https and self certified certificate.
What I tried:
1 - http request: it works fine on google home device and my local machine,
2 - https request: it works on my local machine but not on google home device.
Code I use:
import fetch from 'node-fetch';
import env from './configFile';
import https, { Agent } from 'https';
export default function get(): Promise<any> {
const url = "https://api.url";
const httpsAgent = new https.Agent({
rejectUnauthorized: false,
});
const option = {
method: 'get',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Basic ' + btoa(env.login! + ':' + env.password!),
},
agent: httpsAgent,
};
return fetch(url, option)
.then(res => {
return res.json();
})
.catch(error => {
throw new Error(error);
});
}
Here I disable ssl certification verification. It is something i'll change later because it is not secure, but at least i want to do an https request without error.
My Errors
Go to this link: errors
Reproduce Error
I made a full tutorial, if you want to reproduce the error: https://github.com/killvi/localExecutionHttpsError
In this tuto, i try to make an https request on google to check if I can do it without error. So is not exactly same implementation as mine. But if it works with google, at least i will known that my problem does not come from https implementation in google home device.