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

suggestion: simplify plugin middleware creation #1556

Open
deer opened this issue Aug 1, 2023 · 0 comments
Open

suggestion: simplify plugin middleware creation #1556

deer opened this issue Aug 1, 2023 · 0 comments

Comments

@deer
Copy link
Contributor

deer commented Aug 1, 2023

We currently have:

export interface PluginMiddleware<State = Record<string, unknown>> {
  /** A path in the format of a filename path without filetype */
  path: string;

  middleware: Middleware<State>;
}
export interface Middleware<State = Record<string, unknown>> {
  handler: MiddlewareHandler<State> | MiddlewareHandler<State>[];
}

This is a bit clunky for plugin creators, due to the following syntax:

{
      middleware: {
        handler: twoPointlessMiddlewares,
      },
      path: "lots-of-middleware",
}

Ideally they should just specify the handler and path:

{
      handler: twoPointlessMiddlewares,
      path: "lots-of-middleware",
}

So this suggests a type like the following:

export interface PluginMiddleware<State = Record<string, unknown>> {
  /** A path in the format of a filename path without filetype */
  path: string;
  middleware?: Middleware<State>;
  handler?: MiddlewareHandler<State> | MiddlewareHandler<State>[];
}

While this makes sense now, the downside of this is that if we ever want to add anything to Middleware, then just specifying a handler and path in plugins is no longer valid. Thoughts on this concern, or this suggestion in general? @bjesuiter

from: #1545 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants