| 11 | const regex = /\/cb-\d+\// |
| 12 | |
| 13 | export default function assetPreprocessing(req, res, next) { |
| 14 | if (req.path.startsWith('/assets/')) { |
| 15 | // We're only confident enough to set the *manual* surrogate key if the |
| 16 | // asset contains the cache-busting piece. |
| 17 | if (regex.test(req.url)) { |
| 18 | // We remove it so that when `express.static()` runs, it can |
| 19 | // find the file on disk by its original name. |
| 20 | req.url = req.url.replace(regex, '/') |
| 21 | // The Cache-Control is managed by the configuration |
| 22 | // for express.static() later in the middleware. |
| 23 | } |
| 24 | } |
| 25 | return next() |
| 26 | } |