spee.ch/server/controllers/assets/utils/serveFile.js
2018-12-05 14:54:14 -05:00

19 lines
605 B
JavaScript

const logger = require('winston');
const serveFile = ({ filePath, fileType }, res) => {
if (!fileType) {
logger.error(`no fileType provided for ${filePath}`);
}
const sendFileOptions = {
headers: {
'X-Content-Type-Options' : 'nosniff',
'Content-Type' : fileType,
'Access-Control-Allow-Origin' : '*',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept',
},
};
logger.debug(`fileOptions for ${filePath}:`, sendFileOptions);
res.status(200).sendFile(filePath, sendFileOptions);
};
module.exports = serveFile;