Question - Composing multiple middleware
See original GitHub issueI’m trying to expose a wrapper function so that all my lambda handlers have the same middleware applied to them.
const wrapper = (handler) =>
compose(
// add cors headers last so even error responses from the
// errorHandler middleware have cors headers applied
cors(),
errorHandler(),
jsonSerializer(),
classValidator(),
)(handler)
However I’m struggling to get the type information to line up.
Is it possible to chain these middlewares like this as you can do using middy?
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Chaining multiple pieces of middleware for specific route in ...
Consider following example: const middleware = { requireAuthentication: function(req, res, next) { console.log('private route list!
Read more >Multiple middleware functions #37978 - vercel/next.js - GitHub
I was a bit overwhelmed with multiple middleware, because of our app size, that I put everything in the top level one, from...
Read more >Complete Guide to Express Middleware - Reflectoring
Middleware in Express are functions that come into play after the server receives the request and before the response is sent to the...
Read more >20 Middleware Interview Questions and Answers - CLIMB
Here are 20 commonly asked Middleware interview questions and ... Yes, it is possible to use multiple middlewares for a single application.
Read more >Middleware: Part of the Solution, or Part of the Problem?
In the most general of senses, middleware is software that intermediates functionality or data between two otherwise independent and separate systems.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That’s the same problem - unfortunately currently not fully solvable in TypeScript. I would recommend going with the solution where the handler is wrapped for now until TypeScript has better inference for generics.
Thanks, I’ll adapt it so it also work in strict mode next week 😃