From 6957a4a830040e9917e6788396bbdb1e88271e88 Mon Sep 17 00:00:00 2001 From: "James M. Greene" Date: Tue, 2 Feb 2021 09:43:53 -0600 Subject: [PATCH] Test bypassing Fastly for the Discussions, Packages, and Actions product families (#17611) Co-authored-by: Kevin Heis Co-authored-by: Kevin Heis --- middleware/set-fastly-cache-headers.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/middleware/set-fastly-cache-headers.js b/middleware/set-fastly-cache-headers.js index f7c2140307df..9e6cc02667ca 100644 --- a/middleware/set-fastly-cache-headers.js +++ b/middleware/set-fastly-cache-headers.js @@ -1,7 +1,19 @@ const FASTLY_TTL = process.env.FASTLY_TTL || String(60 * 60 * 24) // 24 hours const STALE_TTL = String(60 * 10) // 10 minutes +const BYPASS_FASTLY = process.env.TEST_BYPASS_FASTLY === 'true' +const BYPASS_PRODUCTS = /^\/([a-z]{2})\/([a-z0-9._-]+@[a-z0-9._-]+\/)?(discussions|packages|actions)(\/.*|$)/i + module.exports = (req, res, next) => { + // Test bypassing Fastly for all pages inside of the Discussions product + if (BYPASS_FASTLY && BYPASS_PRODUCTS.test(req.originalUrl)) { + res.set({ + 'surrogate-control': 'private, no-store', + 'cache-control': 'private, no-store' + }) + return next() + } + res.set({ // Say you want Fastly to cache your content but you don't want it cached by browsers.