Files
unpkg/modules/actions/serveStaticFile.js
Michael Jackson d6fde9fb33 Remove "immutable" from long-term responses
We had a bug recently which sent out some bad "immutable" responses. We
need to have a better process around cutting releases before we can be
sure it doesn't happen again.
2019-01-06 21:10:18 -08:00

27 lines
676 B
JavaScript

const path = require('path');
const etag = require('etag');
const getContentTypeHeader = require('../utils/getContentTypeHeader');
function serveStaticFile(req, res) {
const tags = ['file'];
const ext = path.extname(req.entry.name).substr(1);
if (ext) {
tags.push(`${ext}-file`);
}
res
.set({
'Content-Length': req.entry.size,
'Content-Type': getContentTypeHeader(req.entry.contentType),
'Cache-Control': 'public, max-age=31536000', // 1 year
'Last-Modified': req.entry.lastModified,
ETag: etag(req.entry.content),
'Cache-Tag': tags.join(', ')
})
.send(req.entry.content);
}
module.exports = serveStaticFile;