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

fix(server): add type to Plugin so that MiddlewareHandler is typed correctly #1534

Merged
merged 4 commits into from
Jul 31, 2023

Conversation

deer
Copy link
Contributor

@deer deer commented Jul 27, 2023

closes #1531

So the user's code goes from:

export function getLoggerHandler(logSender?: RemoteLogSenderFunction): Plugin {
  const handler: MiddlewareHandler<Logger> = async function (
    _req: Request,
    ctx: MiddlewareHandlerContext<Logger>
  ) {
    ctx.state.logger = new LogModule(logSender);
    return await ctx.next();
  };

  return {
    name: "loggerPlugin",
    middlewares: [
      {
        middleware: {
          handler: handler as MiddlewareHandler<Record<"logger", unknown>>,
        },
        path: "/",
      },
    ],
  };
}

to

export function getLoggerHandler(logSender?: RemoteLogSenderFunction): Plugin<Logger> {
  const handler: MiddlewareHandler<Logger> = async function (
    _req: Request,
    ctx: MiddlewareHandlerContext<Logger>
  ) {
    ctx.state.logger = new LogModule(logSender);
    return await ctx.next();
  };

  return {
    name: "loggerPlugin",
    middlewares: [
      {
        middleware: {
          handler: handler,
        },
        path: "/",
      },
    ],
  };
}

Thoughts?

@deer
Copy link
Contributor Author

deer commented Jul 27, 2023

Hmmm, the test plugin should probably also use this...

Copy link
Collaborator

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@marvinhagemeister marvinhagemeister merged commit 1ad29e2 into denoland:main Jul 31, 2023
6 checks passed
@deer deer deleted the 1531_plugin_types branch July 31, 2023 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Plugins] PluginMiddleware Type isn't conforms to existing Type ?
3 participants