Javascript 从firebase云函数调用函数

Javascript 从firebase云函数调用函数,javascript,firebase,function,google-cloud-functions,Javascript,Firebase,Function,Google Cloud Functions,也许这是个简单的问题,但我不明白怎么做。 我想从Firebase云函数中的另一个函数调用函数 exports.firstFunction = functions.https.onCall((params, context) => { return new Promise((resolve, reject) => { return secondFunction() // how can I call secondFunction? .then((resp) =

也许这是个简单的问题,但我不明白怎么做。 我想从Firebase云函数中的另一个函数调用函数

exports.firstFunction = functions.https.onCall((params, context) => {
  return new Promise((resolve, reject) => {
    return secondFunction()  // how can I call secondFunction?
      .then((resp) => resolve(resp))
      .catch((e) => reject(e));
  });
});

exports.secondFunction = functions.https.onCall((params, context) => {
  return new Promise((resolve, reject) => {
    return resolve("secondFunction");
  });
});
使
httpCallable(“secondFunction”)
返回正确的字符串。如果我使用了
httpCallable(“firstFunction”)
我有一个
[错误:内部]

我该怎么做呢?

看看:

exports.firstFunction = functions.https.onCall((params, context) => {
  return new Promise((resolve, reject) => {
    return secondFunctionHandler()
      .then((resp) => resolve(resp))
      .catch((e) => reject(e));
  });
});

const secondFunctionHandler = (params, context) => {
  return new Promise((resolve, reject) => {
    return resolve("secondFunction");
  });
};

exports.secondFunction = functions.https.onCall(secondFunctionHandler);

我喜欢将所有云函数分离为“处理程序”(在单独的文件中编写,然后导入)和索引文件中的单行,而不仅仅是我想要重用的那些。它发现它使代码更具可读性和可管理性。

使用
firebase部署-仅函数
,是否将
secondFunctionHandler()
上载到firebase云上?
secondFunctionHandler
只是一个变量。这就像做
constone=1
one
是否上载到Firebase云上?@stratuba在您描述的工作流中,您是否需要多次初始化数据库和其他Firebase资源,每次在每个功能文件中初始化一次?除了
admin
,还需要初始化哪些其他资源?出于可读性目的,我确实喜欢导出
db
变量(它只是
admin.firestore()
)。