问题
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