express-manifest
Middleware which resolves requests based on generic filenames to the associated file fingerprint outlined in a manifest file.
// index.js (example ExpressJS application)
var express = require('express');
var manifest = require('express-manifest');
var app = express();
// view engine configuration...
// template engine configuration...
app.use(manifest({
manifest: path.join(__dirname, 'public') + '/rev-manifest.json',
prepend: path.join(__dirname, 'public'),
reqPathFind: /^(\/?)/,
reqPathReplace: '',
debug: true;
}));
app.use(express.static(path.join(__dirname, 'public')));
// routes configuration...
module.exports = app;
It obtains the incoming request path, replaces any required parts of that string and uses that string as the index within the manifest JSON file, which should return the file path relative to the "prepend" path, then if it finds the file it will send the file to the browser. QED.
{
"javascripts/app.js": "javascripts/app-87efdd3684ac55b9497c.js",
"stylesheets/global.css": "stylesheets/global-692736a41c.css"
}
.
├── index.js
├── bin
│ └── www
├── package.json
├── public
│ ├── javascripts
│ | └── app-87efdd3684ac55b9497c.js
│ └── stylesheets
│ └── global-692736a41c.css
defaults.json file defaults to the following configuration values:
{
"manifest": "./public/rev-manifest.json",
"prepend": "",
"debug": false
}
Path to JSON manifest file relative to your "index.js".
Path to where the static assets are.
The search String / Regex to modify the req.path as you see fit.
What to replace the matching "reqPathFind" value with.
Output useful information to the console. It, obviously, requires for one to hit the server.