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

20 lines
605 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: {
2018-12-05 20:54:14 +01:00
'X-Content-Type-Options' : 'nosniff',
'Content-Type' : fileType,
'Access-Control-Allow-Origin' : '*',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept',
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;