I get the error Error: Can't set headers after they are sent. with the following code.
app.use('/assets/u', express.static('./public/img/u', {
setHeaders: (res, path, stat) => {
redis.get(`image-mime:1`, (err, reply) => {
if (err) console.log(err);
res.set('Content-Type', reply);
});
},
}));
I think it has something to do with the callback? Because it I remove the callback in the following way:
app.use('/assets/u', express.static('./public/img/u', {
setHeaders: (res, path, stat) => {
res.set('Content-Type', 'image/png');
},
}));
everything works like it should and I get no errors. Would love some help on this problem.
Edit: When I turn on the Chrome devtools' "Disable Cache", the error disappears. And the moment I turn it off, the error is back.