2018-04-29 13:00:41 -07:00
|
|
|
const logger = require('winston');
|
|
|
|
|
|
|
|
const serveFile = ({ filePath, fileType }, res) => {
|
2018-07-07 15:03:21 -07:00
|
|
|
if (!fileType) {
|
|
|
|
logger.error(`no fileType provided for ${filePath}`);
|
|
|
|
}
|
2018-04-29 13:00:41 -07:00
|
|
|
const sendFileOptions = {
|
|
|
|
headers: {
|
2018-12-05 14:54:14 -05: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 13:00:41 -07:00
|
|
|
},
|
|
|
|
};
|
2018-07-07 15:03:21 -07:00
|
|
|
logger.debug(`fileOptions for ${filePath}:`, sendFileOptions);
|
2018-05-07 11:03:30 -07:00
|
|
|
res.status(200).sendFile(filePath, sendFileOptions);
|
2018-04-29 13:00:41 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = serveFile;
|