Firebase and external API 404 (firebase functions)

Viewed 1685

I’m trying to get external API with Firebase functions and display information in an Angular app. The angular app is on firebase hosting. Billing is enabled. On localhost, it’s working but on firebase cannot get data.

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

const   express       = require('express')
  , https         = require('https')
  , bodyParser    = require('body-parser')
  , app           = express()
  , cors          = require('cors');


app.use(cors());
app.use(bodyParser.json());

const options = {
  host: 'api.clashofstats.com',
  port: 443,
  path: '/clans/YUPJGL2R/',
  headers: {
    accept: "application/json",
  }
};

app.get("/clan",(req, res) => {
  const request = https.request(options, (response) =>{
    let httpResult = '';
    response.on('data',  (chunk) => {
      httpResult += chunk;
    });
    response.on('end', () => {
      res.send(httpResult);
    });
  });

  request.on('error',(e) => {
    console.log('problem with request: ' + e.message);
  });

  request.end();

});

exports.app = functions.https.onRequest(app);

console log

ERROR e {headers: t, status: 200, statusText: "OK", url: "https://united-clan.cz/clan", ok: false, …}

firebase log

Function execution took 10 ms, finished with status code: 404

network

Request URL: https://united-clan.cz/clan
Request Method: GET
Status Code: 200  (from disk cache)
Remote Address: 151.101.65.195:443
Referrer Policy: no-referrer-when-downgrade

https://us-central1-ucweb-224315.cloudfunctions.net/app 

Cannot GET null
1 Answers
Related