Open
Description
Building on #7 and Azure/azure-functions-nodejs-worker#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:
// 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";
}
});