GoogleCloudPlatform / GoogleCloudPlatform/functions-framework
Lifecyle Hooks
- Dominant language
- No language data
- Stars
- 166
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Description
Certain use-cases require function invocations on certain events related to a container's lifecycle or individual function invocation lifecycle.
Here are some possible examples:
- `on('bad_request', (req, res) => {})`
- Handle bad HTTP request (400)
- `on('startup', (req, res) => {})`
- Invoke once after the container is started and before the first HTTP request.
- `on('shutdown', (req, res) => {})`
- Invoke once before the container is terminated.
- `on('before_function', (req, res) => {})`
- Invoke before every function invocation
- `on('after_function', (req, res) => {})`
- Invoke after every function invocation
An example API could be the following:
```js
functionsframework.on('bad_request', (e, req, res, next) {
if (e.message === "Bad request") {
res.status(400).json({error: {msg: e.message, stack: e.stack}});
}
});
```
---
Feel free to add to this issue for your use-case in a comment.
Contributor guide
Assessment
This issue has not been assessed yet.