Rename server => modules

This commit is contained in:
Michael Jackson
2018-07-31 10:13:26 -07:00
parent 135da0fdc5
commit bef8b2ebee
104 changed files with 13 additions and 13 deletions

View File

@ -0,0 +1,31 @@
const fs = require("fs");
const invariant = require("invariant");
const createAssets = require("./utils/createAssets");
/**
* An express middleware that sets req.assets from the build
* info in the given stats file. Should be used in production.
*/
function staticAssets(webpackStatsFile) {
let stats;
try {
stats = JSON.parse(fs.readFileSync(webpackStatsFile, "utf8"));
} catch (error) {
invariant(
false,
"staticAssets middleware cannot read the build stats in %s; " +
"run the `build` script before starting the server",
webpackStatsFile
);
}
const assets = createAssets(stats);
return (req, res, next) => {
req.assets = assets;
next();
};
}
module.exports = staticAssets;