I’m trying to fetch some remote data (json) using this code:
async function fetchMETData(){
try {
const response = await fetch('https://publicinfobanjir.water.gov.my/wp-content/themes/enlighten/data/met_thunderain.json', {
headers: new Headers({
'Content-Type' : 'application/json',
'User-Agent' : 'ANYTHING_WILL_WORK_HERE'
})
});
const METData = await response.json();
//console.log(METData);
for(var i = 0; i < METData.length; i++){
let existingData = MetThunderRain.findOne({ date: METData[i].Date });
if(existingData === undefined){ //check if the new incoming data is already in the DB. undefined means the data is not in the DB
MetThunderRain.insert({
date : METData[i].Date,
msgEn : METData[i].Msg_EN,
msgMy : METData[i].Msg_MY,
validFrom : METData[i].Valid_from,
validTo : METData[i].Valid_to
})
}
}
} catch (err) {
console.log(err);
}
}
but there is an error on the console that says:
FetchError: request to https://publicinfobanjir.water.gov.my/wp-content/themes/enlighten/data/latestreadings.json failed, reason: unable to verify the first certificate
Tried to search online about this error, and everything is pointing towards the certificate/ssl. This app is currently hosted on Galaxy, and I’ve enabled the Domains & Encryption, as well as Security SSL TLS Protocol Support.
I did use the code below to circumvent this problem while developing on localhost, but won’t implement it on Galaxy for obvious reasons.
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
Anyone can help point me in the right direction? Why is Galaxy’s default SSL certificate isn’t recognised when fetching data externally?