简体   繁体   中英

Firebase cloud functions master handling function

In another stackoverflow post a master handling function that dispatches the processing to different functions was suggested.

    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:

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

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

And in mainpictures.js having the following:

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

When I ran firebase deploy no functions were detected. I was expecting 3. Is this type of structure possible, am I making some obvious mistake in terms of exporting correctly? 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. 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. You can use this API from a required file, if you want, but index.js must still ultimately export a function built like this.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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