Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Do not cache static files if revs mismatch. (#3962)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenba committed Mar 1, 2018
1 parent 0c074e4 commit dc1bc84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions server/src/caching.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ function createCacheSetter(maxAge, flags) {
}
}

exports.doNotCache = createCacheSetter(0);
exports.setMonthlyCache = createCacheSetter(exports.cacheTime);
exports.setDailyCache = createCacheSetter(aDayInSeconds, `s-maxage=${tenMinutesInSeconds}`);
18 changes: 13 additions & 5 deletions server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const gaActivation = require("./ga-activation");
const genUuid = require("nodify-uuid");
const statsd = require("./statsd");
const { notFound } = require("./pages/not-found/server");
const { cacheTime, setMonthlyCache, setDailyCache } = require("./caching");
const { setMonthlyCache, setDailyCache, doNotCache } = require("./caching");
const { captureRavenException, sendRavenMessage,
addRavenRequestHandler, addRavenErrorHandler } = require("./ravenclient");
const { errorResponse, simpleResponse, jsResponse } = require("./responses");
Expand Down Expand Up @@ -184,10 +184,18 @@ app.use((req, res, next) => {
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json({limit: config.requestBodySizeLimit}));

app.use("/static", express.static(path.join(__dirname, "static"), {
index: false,
maxAge: cacheTime ? cacheTime * 1000 : null
}));
app.use(
"/static",
function(req, res, next) {
if (req.query.rev && req.query.rev === linker.getGitRevision()) {
setMonthlyCache(res);
} else {
doNotCache(res);
}
next();
},
express.static(path.join(__dirname, "static"), {index: false})
);

const xpidir = path.join(__dirname, "..", "xpi");
app.use("/xpi", express.static(xpidir, {index: false}));
Expand Down

0 comments on commit dc1bc84

Please sign in to comment.