-
Notifications
You must be signed in to change notification settings - Fork 9
Conversation
Allows to plug in own middleware to server if e.g. the body must not be parsed before using the middleware
I think it would be helpful to have a more detailed example. |
I wonder why not just pass an array of custom "middleware"... which is that looped through with |
My use case for this is by implementing an openid connect server with edgestack there is a generic middleware provided by https://github.com/panva/node-oidc-provider. This middleware has it's own secure interpreter for request bodies. In edgestack's createExpressServer() the bodyParser middleware is used. This prevents streaming libs to get body as stream. This hook allows specific middleware to be attached to the middleware chain before any body/request parsing is done but after security middleware like helmet. This can also be implemented by adding an array of custom middlewares to config, you're right. If you think this is the better way to do it here I'm fine in changing this PR in that way... |
if (config.customMiddleware) | ||
config.customMiddleware.forEach( | ||
(middleware) => { | ||
if (middleware instanceof Array) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
server.use has two signatures
- (middleware, [middleware, ...])
- (pathPrefix, middleware, [middleware, ...])
To support both a middleware and an array of string and middleware is allowed here
Looks good. |
Allows to plug in own middleware to server if e.g. the body must not be parsed before using the middleware