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

20 lines
476 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) {
logger.warn(error);
res.status(404).send();
}
});
2018-04-29 22:00:41 +02:00
};
module.exports = serveFile;