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

18 lines
462 B
JavaScript
Raw Normal View History

2018-04-29 22:00:41 +02:00
const logger = require('winston');
const serveFile = ({ filePath, fileType }, res) => {
if (!fileType) {
logger.error(`no fileType provided for ${filePath}`);
}
2018-04-29 22:00:41 +02:00
const sendFileOptions = {
headers: {
'X-Content-Type-Options': 'nosniff',
'Content-Type' : fileType,
2018-04-29 22:00:41 +02:00
},
};
logger.debug(`fileOptions for ${filePath}:`, sendFileOptions);
2018-05-07 20:03:30 +02:00
res.status(200).sendFile(filePath, sendFileOptions);
2018-04-29 22:00:41 +02:00
};
module.exports = serveFile;