spee.ch/server/controllers/assets/utils/serveFile.js

20 lines
486 B
JavaScript
Raw Normal View History

2018-04-29 22:00:41 +02:00
const logger = require('winston');
const serveFile = ({ filePath, fileType }, res) => {
logger.verbose(`serving file: ${filePath}`);
const sendFileOptions = {
headers: {
'X-Content-Type-Options': 'nosniff',
'Content-Type' : fileType || 'image/jpeg',
},
};
2018-05-04 20:36:09 +02:00
res.status(200).sendFile(filePath, sendFileOptions, (error) => {
if (error) {
2018-05-07 19:51:13 +02:00
logger.warn(filePath, error);
2018-05-04 20:36:09 +02:00
res.status(404).send();
}
});
2018-04-29 22:00:41 +02:00
};
module.exports = serveFile;