Skip to content

Instantly share code, notes, and snippets.

@ockham
Created May 30, 2016 11:53
Show Gist options
  • Save ockham/2892ef443766a51ef32c8a7b77a8c2ac to your computer and use it in GitHub Desktop.
Save ockham/2892ef443766a51ef32c8a7b77a8c2ac to your computer and use it in GitHub Desktop.
commit 08a78d6db7955cf469063d0bc50a5550fa02b0df
Author: Bernhard Reiter <ockham@raz.or.at>
Date: Mon May 30 13:50:35 2016 +0200
Iso-routing: Pass next() to applyMiddlewares()
This way, it will be called in the right order even if there is an async invocation in the mw chain.
diff --git a/server/isomorphic-routing/index.js b/server/isomorphic-routing/index.js
index 3a35066..271c1d2 100644
--- a/server/isomorphic-routing/index.js
+++ b/server/isomorphic-routing/index.js
@@ -13,16 +13,17 @@ export function serverRouter( expressApp, setUpRoute, section ) {
combineMiddlewares(
setSectionMiddlewareFactory( section ),
...middlewares
- )
+ ),
+ serverRender
);
};
}
function combineMiddlewares( ...middlewares ) {
- return function( req, res ) {
+ return function( req, res, next ) {
req.context = getEnhancedContext( req );
applyMiddlewares( req.context, ...middlewares, () => {
- serverRender( req, res );
+ next();
} );
};
}
@ockham
Copy link
Author

ockham commented May 30, 2016

Iso-routing: Pass next() to applyMiddlewares()

This way, it will be called in the right order even if there is an async invocation in the mw chain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment