jimpex
    Preparing search index...

    Function middlewareCreator

    • Generates a configurable middleware for the application to use. It's configurable because the creator, instead of just being sent to the container to mount, it can also be called as a function with custom parameters the middleware can receive.

      Type Parameters

      Parameters

      • creator: CreatorFn

        A function that will generate a middleware.

      Returns ResourceCreator<"middleware", "connect", CreatorFn, MiddlewareConnectFn>

        const myMiddleware = middlewareCreator((options = {}) => (app) => {
      const message = options.message || 'Hello Charo!';
      const responsesBuilder = app.get<ResponsesBuilder>('responsesBuilder');
      return (_, res) => {
      responsesBuilder.json({ res, data: { message } });
      };
      });

      // ...
      container.use(myMiddleware);
        container.use(myMiddleware({ message: 'Hello Pili!' }));