This is a template for firebase cloud functions.
- https://firebase.google.com/docs/functions/typescript
- https://firebase.google.com/docs/hosting/functions
- Typescrpt
- Express.js
- Firebase CLI
- Node 10.17.0
- tsc
To run on localhost, you have to setup your firebase project as below.
$ firebase login
$ firebase use "<your project id>"
Then, you can access the functions via this URL.
http://localhost:5000/your-firebase-project-id/your-firebase-project-region/api/userinfo/userinfo
TypeScript Interfaces used globally
Express middleware created by yourself
Database models adjust to table structure
Database CURD and external API call.
HTTP Request handlers. One endpoint is in one file to divide names for Firebase Cloud Functions.
How to Export router
export const login: IRoutes = {
name: genFunctionName(__dirname, __filename),
router
};
You have to export router object with name property. Function name is formed by combination of directory name and file name.
About routing path
router.post('/', (req: Request, res: Response) => {
// Do Something
});
It is recommended to define path as '/'.
Because all endpoints will be exported to Firebase Cloud Functions indevidually with defferent names.
Business Logic
$ cd functions
# install dependencies
$ yarn install
# ts to js
$ yarn build
# run on localhost
$ firebase serve