Firebase 云函数 http 请求到另一个 firebase 云函数
Firebase cloud function http request to another firebase cloud function
我有一个具有主要功能的主要 Firebase 云功能。但是我需要创建另一个更具体的,它使用主要云功能上的功能。我可以使用免费帐户请求 http Post 或从一个 firebase 云函数获取到另一个 firebase 云函数吗?
我尝试成功,但收到 'ENOTFOUND' 消息,我想知道是我的代码有问题还是只是免费帐户的限制。
index.js
'use strict';
const functions = require('firebase-functions');
const express = require('express');
const app = express();
app.post('/test', function(req, res) {
var request = require('request')
var options = {
method: 'post',
body: req.body, // re-send the incoming body to the main cloud function
json: true,
url: '<main cloud url>',
headers: req.headers // re-send the incoming headers the main cloud function
}
request(options, function (err, response, body) {
if (err || response.statusCode != 200) {
res.status(400).send(err); //re-send the received error to the client
return
}
res.send(body); //re-send the received response to the client
});
});
exports.checkAtivation = functions.https.onRequest(app);
Spark 计划目前无法从另一个 HTTP 云函数调用一个 HTTP 云函数。您将必须升级到 Blaze 计划。
一个项目的功能通过HTTP调用其他功能大多没有意义。如果您只是将逻辑抽象为所有端点可以共享的单个函数或模块,则项目中的所有代码都可以在所有函数之间共享。
我有一个具有主要功能的主要 Firebase 云功能。但是我需要创建另一个更具体的,它使用主要云功能上的功能。我可以使用免费帐户请求 http Post 或从一个 firebase 云函数获取到另一个 firebase 云函数吗?
我尝试成功,但收到 'ENOTFOUND' 消息,我想知道是我的代码有问题还是只是免费帐户的限制。
index.js'use strict';
const functions = require('firebase-functions');
const express = require('express');
const app = express();
app.post('/test', function(req, res) {
var request = require('request')
var options = {
method: 'post',
body: req.body, // re-send the incoming body to the main cloud function
json: true,
url: '<main cloud url>',
headers: req.headers // re-send the incoming headers the main cloud function
}
request(options, function (err, response, body) {
if (err || response.statusCode != 200) {
res.status(400).send(err); //re-send the received error to the client
return
}
res.send(body); //re-send the received response to the client
});
});
exports.checkAtivation = functions.https.onRequest(app);
Spark 计划目前无法从另一个 HTTP 云函数调用一个 HTTP 云函数。您将必须升级到 Blaze 计划。
一个项目的功能通过HTTP调用其他功能大多没有意义。如果您只是将逻辑抽象为所有端点可以共享的单个函数或模块,则项目中的所有代码都可以在所有函数之间共享。