Azure / Azure/azure-functions-nodejs-library
Filtering hooks
- Dominant language
- TypeScript
- Stars
- 70
- Forks
- 35
- Avg merge
- 4d 18h
- Merged PRs (30d)
- 6
Description
_Building on #7 and https://github.com/Azure/azure-functions-nodejs-worker/issues/664._
When a `preInvocation` and `postInvocation` hook is defined it will be executed for every single Function that gets executed, but there may be scenarios where you don't want them to be run every time, here's some examples:
- Performing validation of an inbound HTTP payload for a POST request on a HTTP Trigger
- Creating a `CosmosClient` to provide for Functions that can't use the input/output bindings (for removing or replacing items in a Cosmos collection)
- Only executing for a certain trigger type in an app that has multiple different trigger types in use
Here's a pseudocode API:
```ts
// only apply to a specific trigger type
app.preInvocation({
hook: () => {},
filter: 'timer'
});
// filter based on a function name
app.preInvocation({
hook: () => {},
filter: (context) => {
return context.functionName.contains('Delete') || context.functionName.contains('Put');
}
});
// filter based on some custom logic
app.preInvocation({
hook: () => {},
filter: (context) => {
return context.trigger.type === 'httpTrigger' && context.trigger.payload.method === "POST";
}
});
```
Contributor guide
Assessment
This issue has not been assessed yet.