https://github.com/laurentpellegrino/cloud-functions-loader
Exports Cloud Functions for Firebase with scale in mind.
https://github.com/laurentpellegrino/cloud-functions-loader
cloud-functions cloud-functions-emulator firebase firebase-database
Last synced: 3 months ago
JSON representation
Exports Cloud Functions for Firebase with scale in mind.
- Host: GitHub
- URL: https://github.com/laurentpellegrino/cloud-functions-loader
- Owner: laurentpellegrino
- License: apache-2.0
- Created: 2017-10-17T15:28:52.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-17T16:44:27.000Z (over 8 years ago)
- Last Synced: 2026-03-11T12:09:53.055Z (4 months ago)
- Topics: cloud-functions, cloud-functions-emulator, firebase, firebase-database
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# cloud-functions-exporter
Exports Google Cloud Functions with scale in mind.
This package was inspired by a discussion started on Medium:
https://codeburst.io/organizing-your-firebase-cloud-functions-67dc17b3b0da
## Conventions
The purpose is to keep each function source code isolated in its own file to
ease maintenance. For the package to work properly, you have to following these
conventions:
- Put each function code in a dedicated file (optionally in a directory hierarchy).
- Each function file must use the camel case for its name but also end with `.js`.
- Register the path to the function source code for loading by this module.
In most of the cases, this solution also provides performance improvements since
each function loads only the dependencies it needs.
Besides, not all functions are exported to Google Cloud Functions runtime, which has
small benefits on cold-starts.
## Usage example
The main `index.js`:
```
require('@noticeable/cloud-functions-loader')({
'api/env.js': false,
'api/headers.js': false,
'auth/onCreate.js': true,
'auth/onDelete.js': true,
'firestore/accessTokens/onCreate.js': true,
'firestore/accessTokens/onDelete.js': true,
'firestore/pendingWebhookActions/onCreate.js': true,
'firestore/posts/onCreate.js': true,
'firestore/posts/onDelete.js': true,
'firestore/posts/onUpdate.js': true,
'firestore/projects/onCreate.js': true,
'firestore/projects/onDelete.js': true,
'firestore/projects/onUpdate.js': true,
'firestore/users/onDelete.js': true
});
```
The definition for `api/env.js`:
```
const functions = require('firebase-functions');
exports = module.exports = functions.https.onRequest((req, res) => {
res.send(200, {
'date': new Date(),
'env': process.env
});
});
```