Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Commit

Permalink
fix: crash in lazy mode
Browse files Browse the repository at this point in the history
In lazy mode, res.locals.webpackStats is undefined
  • Loading branch information
Sergey Tatarintsev committed Nov 14, 2016
1 parent af6cb8d commit 4a7b36d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,7 @@ function testPathToChunkUrl(testPath) {
*/
function middleware(routeBuilder) {
return function middleware(req, res, next) {
const commonAssetsObj = _.omitBy(
res.locals.webpackStats.toJson().assetsByChunkName,
value => /\.bundle.js$/.test(value)
);
const commonAssets = Object.keys(commonAssetsObj).reduce((result, item) => {
result.push(assetsRoot() + commonAssetsObj[item]);
return result;
}, []);

const commonAssets = readCommonAssets(res.locals.webpackStats);
log(`request to ${req.path}`);
if (routeBuilder.isUrlRegistered(req.path)) {
log('this is a test page url');
Expand All @@ -48,6 +40,19 @@ function middleware(routeBuilder) {
};
}

function readCommonAssets(webpackStats) {
if (!webpackStats) {
return [];
}
const commonAssetsObj = _.omitBy(
webpackStats.toJson().assetsByChunkName,
value => /\.bundle.js$/.test(value)
);
return Object.keys(commonAssetsObj).reduce((result, item) => {
result.push(assetsRoot() + commonAssetsObj[item]);
return result;
}, []);
}

exports.testPathToChunkName = testPathToChunkName;
exports.testPathToChunkUrl = testPathToChunkUrl;
Expand Down

0 comments on commit 4a7b36d

Please sign in to comment.