| 20 | } |
| 21 | |
| 22 | function getBuffer(filePath) { |
| 23 | let buffer |
| 24 | if (!fs.existsSync(filePath)) { |
| 25 | throw new Error(`${filePath} not found on disk`) |
| 26 | } |
| 27 | return () => { |
| 28 | if (!buffer) { |
| 29 | // Yes, sync and a bit slow, but the headers we send will |
| 30 | // make sure these requests are rare because the payload |
| 31 | // will be sticky in the CDN and stickly in the browser too. |
| 32 | buffer = fs.readFileSync(filePath) |
| 33 | } |
| 34 | return buffer |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | export default function favicons(req, res, next) { |
| 39 | if (!MAP[req.path]) return next() |