简体   繁体   English

Firebase 云函数主处理函数

[英]Firebase cloud functions master handling function

In another stackoverflow post a master handling function that dispatches the processing to different functions was suggested.另一个 stackoverflow 帖子中,建议了一个主处理函数,它将处理分派到不同的函数。

    functions.storage.object().onFinalize((object) => {
      if (object.name.startsWith('User_Pictures/')) {    
        return handleUserPictures(object);
      } else if (object.name.startsWith('MainCategoryPics/')) {
        return handleMainCategoryPictures(object);
      }
    })

I have tried implementing this by having index.js as follows:我尝试通过使用index.js来实现这一点,如下所示:

const handler = require('./handler');
exports.handler = handler.handler;

exports.userpictures = require('./userpictures');
exports.mainpictures = require('./mainpictures');

And in mainpictures.js having the following:mainpictures.js具有以下内容:

exports.handleMainCategoryPictures= async (object) => { ... code here ... }

When I ran firebase deploy no functions were detected.当我运行firebase deploy没有检测到任何功能。 I was expecting 3. Is this type of structure possible, am I making some obvious mistake in terms of exporting correctly?我期待 3. 这种类型的结构是否可能,我是否在正确导出方面犯了一些明显的错误? When I tried exporting directly without the handler the functions were detected.当我尝试在没有处理程序的情况下直接导出时,检测到了这些功能。

You still need to define your exported functions with the functions builder API.您仍然需要使用函数构建器 API 定义导出的函数。 That's thing that goes like this in your first code bit:在你的第一个代码位中就是这样的:

export fun = functions.storage.object().onFinalize(...)

If you aren't using this API to build and export functions from index.js, then the Firebase CLI will find no function, and nothing will be deployed.如果您不使用此 API 从 index.js 构建和导出函数,则 Firebase CLI 将找不到任何函数,也不会部署任何内容。 You can use this API from a required file, if you want, but index.js must still ultimately export a function built like this.如果需要,您可以从所需文件中使用此 API,但 index.js 最终仍必须导出这样构建的函数。

If you are, in fact, using this and not showing it here, then I suggest you edit the question to show the complete, minimal example of all the files in play.如果您实际上正在使用它而不在此处显示它,那么我建议您编辑问题以显示所有正在播放的文件的完整、最小示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM