Skip to content
This repository has been archived by the owner on Nov 15, 2017. It is now read-only.

Adds hooks to createExpressServer #130

Merged
merged 7 commits into from
Mar 30, 2017
Merged

Adds hooks to createExpressServer #130

merged 7 commits into from
Mar 30, 2017

Conversation

fastner
Copy link
Member

@fastner fastner commented Mar 24, 2017

Allows to plug in own middleware to server if e.g. the body must not be parsed before using the middleware

Allows to plug in own middleware to server if e.g. the body must not be parsed before using the middleware
@swernerx
Copy link
Member

I think it would be helpful to have a more detailed example.

@swernerx
Copy link
Member

I wonder why not just pass an array of custom "middleware"... which is that looped through with server.use(custom[xxx])

@fastner
Copy link
Member Author

fastner commented Mar 24, 2017

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)
Copy link
Member Author

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

@swernerx
Copy link
Member

Looks good.

@swernerx swernerx merged commit f8ce97b into master Mar 30, 2017
@swernerx swernerx deleted the feature/server-hooks branch March 30, 2017 13:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants