firebase functions and external API

浪尽此生 提交于 2020-01-24 20:30:46

问题


const functions = require('firebase-functions');
exports.apiResponse = functions.https.onRequest((request, response) => {
const url = "https://test-proj-heroku.herokuapp.com/api/plans"
const https = require('https');
  var req = https.get(url, (resp) => {
    let data = '';
    resp.on('data', (chunk) => { data += chunk; });
    resp.on('end', () => {
        var result = JSON.parse(data);
        response.send({ fulfillmentText: "Firebase 🔥 API Is Running..." });
      });
    }).on("error", (err) => { console.log("Error: " + err.message); });
});

Why this cloud function is not responding? Deploed on this URL = https://us-central1-ayyanalee-e891b.cloudfunctions.net/apiResponse.


回答1:


You are trying to make a request to your Heroku server (a non-Google product) and it appears that you are on the free tier of Firebase. As the pricing page indicates, under the Cloud Functions portion section, free-tiers are only permitted to make Outbound Networking actions (such as the call to your Heroku server) to other Google services (such as Gmail, Google Drive, etc...)

If you want to make requests to your Heroku server, you'll need to upgrade to a paid Firebase tier.



来源:https://stackoverflow.com/questions/51123462/firebase-functions-and-external-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!