Spec
Spec

Reputation: 35

Firebase Functions index.ts

So I am using firebase functions, as my API request with some functions doing some work, Right now I have 1 'index.ts' file and all of my functions inside (14 functions) there with this signature:

export const $function1 = functions.region(#region).runWith({ memory: '512MB' }).https.onRequest

export const $function2 = functions.region(#region).https.onCall(async (data, context) => {

Now my question is about organize this 'index.ts',

Some of my https requests verify token and check for valid body request,

What is the best way to organize this 'index.ts' file?

How exactly I am exporting it from files in this folder without initialize the admin sdk every time?

I am trying to make this folder organize as I can as in the future I need to add more and more functions..

Thanks for the help!

Upvotes: 0

Views: 1062

Answers (1)

Methkal Khalawi
Methkal Khalawi

Reputation: 2477

This is really a personal preference but the recommended way to organize functions by Firebase documentation is to write all your functions in their own files, export them then initialize them all in one index.ts file[1]. You can also group your functions depending on their purpose like auth or logging ...etc then export them to one index.ts file. For more info, check the documentation I have shared but as I said, you can always organize them in your own way.

[1]https://firebase.google.com/docs/functions/organize-functions

Upvotes: 2

Related Questions