1
0
mirror of synced 2026-01-04 18:06:26 -05:00

repo sync

This commit is contained in:
Octomerger Bot
2021-02-03 07:55:47 +10:00
committed by GitHub
3 changed files with 17 additions and 6 deletions

View File

@@ -38,7 +38,6 @@ module.exports = function (app) {
// *** Headers ***
app.use(require('compression')())
app.use(require('./set-fastly-cache-headers'))
app.use(require('./disable-caching-on-safari'))
// *** Config and context for redirects ***
@@ -93,6 +92,9 @@ module.exports = function (app) {
app.use(instrument('./featured-links'))
app.use(instrument('./learning-track'))
// *** Headers for pages only ***
app.use(require('./set-fastly-cache-headers'))
// *** Rendering, must go last ***
app.get('/*', asyncMiddleware(instrument('./render-page')))
app.use(require('./handle-errors'))

View File

@@ -1,12 +1,12 @@
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._-]+\/)?github(\/.*|$)/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)) {
const BYPASS_FASTLY = process.env.TEST_BYPASS_FASTLY === 'true'
// Bypass Fastly caching for all rendered pages
if (BYPASS_FASTLY) {
// Disallow both Fastly AND the browser from caching HTML pages
res.set({
'surrogate-control': 'private, no-store',
'cache-control': 'private, no-store'

View File

@@ -66,6 +66,15 @@ describe('server', () => {
expect(res.headers['surrogate-key']).toBe('all-the-things')
})
test('sets Fastly cache control headers to bypass if enabled', async () => {
process.env.TEST_BYPASS_FASTLY = 'true'
const res = await get('/en')
expect(res.headers['cache-control']).toBe('private, no-store')
expect(res.headers['surrogate-control']).toBe('private, no-store')
expect(res.headers).not.toHaveProperty('surrogate-key')
})
test('does not render duplicate <html> or <body> tags', async () => {
const $ = await getDOM('/en')
expect($('html').length).toBe(1)