refac
This commit is contained in:
17
src/server/routes/images.js
Normal file
17
src/server/routes/images.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import path from 'path';
|
||||
|
||||
export function registerImages(app, cacheDir) {
|
||||
app.get('/img/cat/:id.avif', (req, res) => {
|
||||
const { id } = req.params;
|
||||
const imagePath = path.join(cacheDir, 'img', 'categories', `${id}.avif`);
|
||||
|
||||
// Cache images for 1 year (immutable content)
|
||||
res.set('Cache-Control', 'public, max-age=31536000, immutable');
|
||||
|
||||
res.sendFile(path.resolve(imagePath), (err) => {
|
||||
if (err) {
|
||||
res.status(404).send('Image not found');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user