Falborian
Falborian

Reputation: 1

Cloud functions - could not handle the request

I am trying to fetch data from third party API (api.pubgtracker.com) by using reverse proxy to add CORS headers to the request.

My index.js looks like this:

const functions = require('firebase-functions');
const fetch = require('node-fetch')

exports.findPlayer = functions.https.onRequest((req, res) => {
 let nickname = req.query.nickname;
 let region = req.query.region;
 let mode = req.query.mode;

 let requestHeader = {
  method: "GET",
   headers: {
     'my-api-key': 'value-of-my-api-key'
   }
 }

 fetch(`https://cors-anywhere.herokuapp.com/https://api.pubgtracker.com/v2/profile/pc/${nickname}?region=${region}&mode=${mode}`, requestHeader)
   .then(response => response)
   .then(text => {
     res.send(text);
   });
});

Problem is that by going to my cloud function, all I get is "Error: Could not handle the request" and by looking into logs I see:

FetchError: request to https://cors-anywhere.herokuapp.com/https://api.pubgtracker.com/v2/profile/pc/VissGames?region=na&mode=solo-fpp failed, reason: getaddrinfo ENOTFOUND cors-anywhere.herokuapp.com cors-anywhere.herokuapp.com:443

What's the problem here? I am a pure beginner when it comes to fetching data and I am not able to see what's wrong, despite trying to solve it through solutions other people gave on questions with similar problem.

Upvotes: 0

Views: 2591

Answers (1)

Ishan Thilina Somasiri
Ishan Thilina Somasiri

Reputation: 1244

I checked whether https://cors-anywhere.herokuapp.com/ is working. Your application is complaining ENOTFOUND for cors-anywhere.herokuapp.com:443. That means it cannot access https://cors-anywhere.herokuapp.com/. This means it does not have proper network connectivity or there's a problem with your DNS.

Can provide more help if you give us more data. (Ex : Try accessing a different URL such as google.com)

Upvotes: 1

Related Questions