Skip to content

Middleware should be provided to the serve function, not the client #438

Open
@samtgarson

Description

@samtgarson

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 using inngest.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

  1. Register a middleware in the inngest client which imports a non-webpackable client, like import { setTags } from '@appsignal/nodejs'
  2. Call inngest.send from Next.js middleware
  3. See various webpack errors trying to import the AppSignal server package

Expected 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

  • inngest-cli version: 0.23.0
  • inngest 3.6.2

Metadata

Metadata

Assignees

Labels

⬆️ improvementPerformance, reliability, or usability improvements📦 inngestAffects the `inngest` package

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions