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.
creator
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); Copy
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!' })); Copy
container.use(myMiddleware({ message: 'Hello Pili!' }));
A function that will generate a middleware.
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.Example: Basic usage
Example: Custom parameters