Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtering hooks #64

Open
aaronpowell opened this issue Mar 9, 2023 · 0 comments
Open

Filtering hooks #64

aaronpowell opened this issue Mar 9, 2023 · 0 comments

Comments

@aaronpowell
Copy link
Contributor

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";
  }
});
@ejizba ejizba added this to the Backlog Candidates milestone Apr 3, 2023
@ejizba ejizba added the P2 label Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants