-
Notifications
You must be signed in to change notification settings - Fork 43
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
Middleware should be provided to the serve function, not the client #438
Comments
(Update: importing |
Hi @samtgarson 👋 Thanks for reporting. I empathise with the annoyance here. Middleware can also be used to hook into the lifecycle for sending events with In your case, I'd recommend creating and importing a separate client for use in the edge environment for sending events, which gives you the chance to ensure only relevant middleware is used in the more restrictive edge environment. I'll add a change to our docs to call out this workaround. We're not 100% happy with the interaction between |
Hey @jpwilliams thanks for the reply. I missed that middleware can hook into sending. It didn't occur to me to make a second client, this seems to have worked (with a hefty comment to explain to other engineers when to use which client 😅) Agreed, this isn't ideal—it might make sense to provide a second "serve only middleware" option to |
Describe the bug
As far as I can tell, middleware is only actually executed during function runs, however we have to register them (globally, at least) in the client.
This is problematic if we need to use libraries which are not able to be imported in all the contexts that the inngest client might be used.
For example:
@appsignal/nodejs
is not able to be imported in the Next.js Edge runtime due to webpack issues, and we would like to be able to set tags and capture errors in functions using AppSignal. However, we also need to trigger functions usinginngest.send
in Edge functions and Next-Auth callbacks, which run in middleware (and therefore the Edge Runtime).It would make sense to me (if my understanding is correct) that there's no reason the client needs to know about middleware at the point of triggering events, only at the point of running functions.
To Reproduce
import { setTags } from '@appsignal/nodejs'
inngest.send
from Next.js middlewareExpected behavior
I should be able to trigger events without having to import server only packages.
Screenshots / Stack trace dump
If applicable, add screenshots or paste what is output in your terminal to help explain your problem.
System info
The text was updated successfully, but these errors were encountered: