Merge branch 'master' into firebase-hosting
This commit is contained in:
commit
0baa63d525
|
@ -20,7 +20,7 @@ export default function serveHTMLModule(req, res) {
|
||||||
.set({
|
.set({
|
||||||
'Content-Length': Buffer.byteLength(code),
|
'Content-Length': Buffer.byteLength(code),
|
||||||
'Content-Type': getContentTypeHeader(req.entry.contentType),
|
'Content-Type': getContentTypeHeader(req.entry.contentType),
|
||||||
'Cache-Control': 'public, max-age=31536000, immutable', // 1 year
|
'Cache-Control': 'public, max-age=31536000', // 1 year
|
||||||
ETag: etag(code),
|
ETag: etag(code),
|
||||||
'Cache-Tag': 'file, html-file, html-module'
|
'Cache-Tag': 'file, html-file, html-module'
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,7 +14,7 @@ export default function serveJavaScriptModule(req, res) {
|
||||||
.set({
|
.set({
|
||||||
'Content-Length': Buffer.byteLength(code),
|
'Content-Length': Buffer.byteLength(code),
|
||||||
'Content-Type': getContentTypeHeader(req.entry.contentType),
|
'Content-Type': getContentTypeHeader(req.entry.contentType),
|
||||||
'Cache-Control': 'public, max-age=31536000, immutable', // 1 year
|
'Cache-Control': 'public, max-age=31536000', // 1 year
|
||||||
ETag: etag(code),
|
ETag: etag(code),
|
||||||
'Cache-Tag': 'file, js-file, js-module'
|
'Cache-Tag': 'file, js-file, js-module'
|
||||||
})
|
})
|
||||||
|
|
|
@ -35,7 +35,7 @@ export default function serveMetadata(req, res) {
|
||||||
|
|
||||||
res
|
res
|
||||||
.set({
|
.set({
|
||||||
'Cache-Control': 'public, max-age=31536000, immutable', // 1 year
|
'Cache-Control': 'public, max-age=31536000', // 1 year
|
||||||
'Cache-Tag': 'meta'
|
'Cache-Tag': 'meta'
|
||||||
})
|
})
|
||||||
.send(metadata);
|
.send(metadata);
|
||||||
|
|
|
@ -15,7 +15,7 @@ export default function serveStaticFile(req, res) {
|
||||||
.set({
|
.set({
|
||||||
'Content-Length': req.entry.size,
|
'Content-Length': req.entry.size,
|
||||||
'Content-Type': getContentTypeHeader(req.entry.contentType),
|
'Content-Type': getContentTypeHeader(req.entry.contentType),
|
||||||
'Cache-Control': 'public, max-age=31536000, immutable', // 1 year
|
'Cache-Control': 'public, max-age=31536000', // 1 year
|
||||||
'Last-Modified': req.entry.lastModified,
|
'Last-Modified': req.entry.lastModified,
|
||||||
ETag: etag(req.entry.content),
|
ETag: etag(req.entry.content),
|
||||||
'Cache-Tag': tags.join(', ')
|
'Cache-Tag': tags.join(', ')
|
||||||
|
|
|
@ -9,10 +9,9 @@ import getNpmPackageInfo from '../utils/getNpmPackageInfo';
|
||||||
function tagRedirect(req, res) {
|
function tagRedirect(req, res) {
|
||||||
const version = req.packageInfo['dist-tags'][req.packageVersion];
|
const version = req.packageInfo['dist-tags'][req.packageVersion];
|
||||||
|
|
||||||
// Cache tag redirects for 1 minute.
|
|
||||||
res
|
res
|
||||||
.set({
|
.set({
|
||||||
'Cache-Control': 'public, max-age=60',
|
'Cache-Control': 'public, max-age=300', // 5 minutes
|
||||||
'Cache-Tag': 'redirect, tag-redirect'
|
'Cache-Tag': 'redirect, tag-redirect'
|
||||||
})
|
})
|
||||||
.redirect(
|
.redirect(
|
||||||
|
@ -28,10 +27,9 @@ function semverRedirect(req, res) {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (maxVersion) {
|
if (maxVersion) {
|
||||||
// Cache semver redirects for 1 minute.
|
|
||||||
res
|
res
|
||||||
.set({
|
.set({
|
||||||
'Cache-Control': 'public, max-age=60',
|
'Cache-Control': 'public, max-age=300', // 5 minutes
|
||||||
'Cache-Tag': 'redirect, semver-redirect'
|
'Cache-Tag': 'redirect, semver-redirect'
|
||||||
})
|
})
|
||||||
.redirect(
|
.redirect(
|
||||||
|
@ -92,7 +90,7 @@ function filenameRedirect(req, res) {
|
||||||
// and URLs resolve correctly.
|
// and URLs resolve correctly.
|
||||||
res
|
res
|
||||||
.set({
|
.set({
|
||||||
'Cache-Control': 'public, max-age=31536000, immutable', // 1 year
|
'Cache-Control': 'public, max-age=31536000', // 1 year
|
||||||
'Cache-Tag': 'redirect, filename-redirect'
|
'Cache-Tag': 'redirect, filename-redirect'
|
||||||
})
|
})
|
||||||
.redirect(
|
.redirect(
|
||||||
|
|
|
@ -12,7 +12,7 @@ function indexRedirect(req, res, entry) {
|
||||||
// resolve correctly.
|
// resolve correctly.
|
||||||
res
|
res
|
||||||
.set({
|
.set({
|
||||||
'Cache-Control': 'public, max-age=31536000, immutable', // 1 year
|
'Cache-Control': 'public, max-age=31536000', // 1 year
|
||||||
'Cache-Tag': 'redirect, index-redirect'
|
'Cache-Tag': 'redirect, index-redirect'
|
||||||
})
|
})
|
||||||
.redirect(
|
.redirect(
|
||||||
|
@ -94,24 +94,26 @@ function searchEntries(tarballStream, entryName, wantsIndex) {
|
||||||
|
|
||||||
const chunks = [];
|
const chunks = [];
|
||||||
|
|
||||||
stream.on('data', chunk => chunks.push(chunk)).on('end', () => {
|
stream
|
||||||
const content = Buffer.concat(chunks);
|
.on('data', chunk => chunks.push(chunk))
|
||||||
|
.on('end', () => {
|
||||||
|
const content = Buffer.concat(chunks);
|
||||||
|
|
||||||
// Set some extra properties for files that we will
|
// Set some extra properties for files that we will
|
||||||
// need to serve them and for ?meta listings.
|
// need to serve them and for ?meta listings.
|
||||||
entry.contentType = getContentType(entry.name);
|
entry.contentType = getContentType(entry.name);
|
||||||
entry.integrity = getIntegrity(content);
|
entry.integrity = getIntegrity(content);
|
||||||
entry.lastModified = header.mtime.toUTCString();
|
entry.lastModified = header.mtime.toUTCString();
|
||||||
entry.size = content.length;
|
entry.size = content.length;
|
||||||
|
|
||||||
// Set the content only for the foundEntry and
|
// Set the content only for the foundEntry and
|
||||||
// discard the buffer for all others.
|
// discard the buffer for all others.
|
||||||
if (entry === foundEntry) {
|
if (entry === foundEntry) {
|
||||||
entry.content = content;
|
entry.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue