checkStaticImageFormat middleware

This commit is contained in:
Simon Martín
2018-05-11 17:41:00 +02:00
parent e5ddd57d65
commit 7112341c51
@@ -0,0 +1,11 @@
const VALID_IMAGE_FORMATS = ['png', 'jpg', 'jpeg'];
module.exports = function checkStaticImageFormat () {
return function checkStaticImageFormatMiddleware (req, res, next) {
if(!VALID_IMAGE_FORMATS.includes(req.params.format.toLowerCase())) {
return next(new Error(`Unsupported image format "${req.params.format}"`));
}
next();
};
};