File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,7 +38,6 @@ module.exports = function (app) {
3838
3939 // *** Headers ***
4040 app . use ( require ( 'compression' ) ( ) )
41- app . use ( require ( './set-fastly-cache-headers' ) )
4241 app . use ( require ( './disable-caching-on-safari' ) )
4342
4443 // *** Config and context for redirects ***
@@ -93,6 +92,9 @@ module.exports = function (app) {
9392 app . use ( instrument ( './featured-links' ) )
9493 app . use ( instrument ( './learning-track' ) )
9594
95+ // *** Headers for pages only ***
96+ app . use ( require ( './set-fastly-cache-headers' ) )
97+
9698 // *** Rendering, must go last ***
9799 app . get ( '/*' , asyncMiddleware ( instrument ( './render-page' ) ) )
98100 app . use ( require ( './handle-errors' ) )
Original file line number Diff line number Diff line change 11const FASTLY_TTL = process . env . FASTLY_TTL || String ( 60 * 60 * 24 ) // 24 hours
22const STALE_TTL = String ( 60 * 10 ) // 10 minutes
33
4- const BYPASS_FASTLY = process . env . TEST_BYPASS_FASTLY === 'true'
5- const BYPASS_PRODUCTS = / ^ \/ ( [ a - z ] { 2 } ) \/ ( [ a - z 0 - 9 . _ - ] + @ [ a - z 0 - 9 . _ - ] + \/ ) ? g i t h u b ( \/ .* | $ ) / i
6-
74module . exports = ( req , res , next ) => {
8- // Test bypassing Fastly for all pages inside of the Discussions product
9- if ( BYPASS_FASTLY && ! BYPASS_PRODUCTS . test ( req . originalUrl ) ) {
5+ const BYPASS_FASTLY = process . env . TEST_BYPASS_FASTLY === 'true'
6+
7+ // Bypass Fastly caching for all rendered pages
8+ if ( BYPASS_FASTLY ) {
9+ // Disallow both Fastly AND the browser from caching HTML pages
1010 res . set ( {
1111 'surrogate-control' : 'private, no-store' ,
1212 'cache-control' : 'private, no-store'
Original file line number Diff line number Diff line change @@ -66,6 +66,15 @@ describe('server', () => {
6666 expect ( res . headers [ 'surrogate-key' ] ) . toBe ( 'all-the-things' )
6767 } )
6868
69+ test ( 'sets Fastly cache control headers to bypass if enabled' , async ( ) => {
70+ process . env . TEST_BYPASS_FASTLY = 'true'
71+
72+ const res = await get ( '/en' )
73+ expect ( res . headers [ 'cache-control' ] ) . toBe ( 'private, no-store' )
74+ expect ( res . headers [ 'surrogate-control' ] ) . toBe ( 'private, no-store' )
75+ expect ( res . headers ) . not . toHaveProperty ( 'surrogate-key' )
76+ } )
77+
6978 test ( 'does not render duplicate <html> or <body> tags' , async ( ) => {
7079 const $ = await getDOM ( '/en' )
7180 expect ( $ ( 'html' ) . length ) . toBe ( 1 )
You can’t perform that action at this time.
0 commit comments