mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-02 12:52:38 +00:00
add content negotiation middleware and tests
This commit is contained in:
12
server/middleware/content-negotiation.js
Normal file
12
server/middleware/content-negotiation.js
Normal file
@@ -0,0 +1,12 @@
|
||||
module.exports = (req, res, next)=>{
|
||||
const isImageRequest = req.get('Accept').split(',')
|
||||
.filter((h)=>!h.includes('q='))
|
||||
.every((h)=>/image\/.*/.test(h));
|
||||
if(isImageRequest) {
|
||||
return res.status(406).send({
|
||||
message : 'Request for image at this URL is not supported'
|
||||
});
|
||||
}
|
||||
|
||||
next();
|
||||
};
|
||||
Reference in New Issue
Block a user