spee.ch/server/controllers/assets/utils/serveFile.js
2018-05-04 11:36:09 -07:00

19 lines
476 B
JavaScript

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',
},
};
res.status(200).sendFile(filePath, sendFileOptions, (error) => {
if (error) {
logger.warn(error);
res.status(404).send();
}
});
};
module.exports = serveFile;