FireBase函数和外部API [英] firebase functions and external API

查看:29
本文介绍了FireBase函数和外部API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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); });
});

为什么这个云函数没有响应?已在此URL上展开= https://us-central1-ayyanalee-e891b.cloudfunctions.net/apiResponse

推荐答案

您正在尝试向您的Heroku服务器(非谷歌产品)发出请求,而您似乎处于FireBase的自由层。如the pricing page所示,在Cloud Functions部分下,自由层仅允许对其他Google服务(如Gmail、Google Drive等.)进行出站联网操作(,如调用您的Heroku服务器)

如果要向Heroku服务器发出请求,则需要升级到付费Firebase层。

这篇关于FireBase函数和外部API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆