Just wondering how you would "Name" your app.get
or app.post
functions so that you can do firebase deploy --only functions:function1, functions:function2
.
const function1 = () = {
app.post('endpoint', {
data
})
}
?
Thanks
CodePudding user response:
I happen to have code that allows me to deploy all my functions, or some of them, at the same time. It scans my directory structure to discover the files, and builds the names from the structure. My structure ends up looking like:
api
|->firestore
|->on-create
|->stripe-logs
|->index.js
....
|->on-write
|->top-group
|->lower-group
|->index.js
......
|->https
|->on-call
|->admin
|->test-customer
|->index.js
|->cancel
|->event
|->index.js
....
|->on-request
|->stripe
|->index.js
....
|->pubsub
|->on-run
|->account-cleanup
|->index.js
This generates function names like:
firestore-onCreate-stripeLogs
firestore-onWrite-topGroup-lowerGroup
https-onCall-admin-testCustomer
https-onCall-cancel-event
https-onRequest-Stripe
pubsub-onRun-accountCleanup
The names clearly indicate HOW the function operates, what it operates FROM, and (at least some) of WHAT it intends to do.
CodePudding user response:
In my personal experience, I used compose the cloud functions name from a few parts (usually with a dash between those parts), following some established naming conventions in a company/product:
- Prefix - a name of a (functional) component to which the given cloud function belongs to. This name is also used as a prefix for all other resources used by the given (functional) component - storage buckets, service accounts, pubsub topics, bigquery datasets, and so on. Usually that prefix should not exceed 10 - 12 characters, and it is expected, that this name is 'globally' unique in the company scope among all functional components.
- A name part - to reflect the purpose/goal/meaning of the cloud function - something distinct among any other cloud functions in the scope of the given functional component. Usually that name should not exceed 10 - 12 characters as well.
- Suffix - some abbreviation to reflect either (a) environment (for example:
prd
,uat
, etc.) in case the deployed cloud function is to be unique in the scope of the GCP project (and/or environment); or (b) in case of development or defect fixing - a specific git branch (or ticket number) - for example:f-9999
,h-9999
, and so on. The latter provides a capability to deploy and use/test many "versions"of the given cloud function (from different git branches) into a shared development environment (shared GCP project) at the same time. Usually that suffix should not exceed 8 characters.
Thus, (visually) looking at the function name - one should be able to understand what is it for, and which environment it belongs to.