@@ -81,6 +81,39 @@ export default function (app) {
8181 app . use ( datadog )
8282 }
8383
84+ // Must appear before static assets and all other requests
85+ // otherwise we won't be able to benefit from that functionality
86+ // for static assets as well.
87+ app . use ( setFastlySurrogateKey )
88+
89+ // Must come before `csrf` otherwise you get a Set-Cookie on successful
90+ // asset requests. And it can come before `rateLimit` because if it's a
91+ // 200 OK, the rate limiting won't matter anyway.
92+ // archivedEnterpriseVersionsAssets must come before static/assets
93+ app . use (
94+ asyncMiddleware (
95+ instrument ( archivedEnterpriseVersionsAssets , './archived-enterprise-versions-assets' )
96+ )
97+ )
98+ app . use (
99+ '/assets' ,
100+ express . static ( 'assets' , {
101+ index : false ,
102+ etag : false ,
103+ lastModified : false ,
104+ maxAge : '1 day' , // Relatively short in case we update images
105+ } )
106+ )
107+ app . use (
108+ '/public' ,
109+ express . static ( 'data/graphql' , {
110+ index : false ,
111+ etag : false ,
112+ lastModified : false ,
113+ maxAge : '7 days' , // A bit longer since releases are more sparse
114+ } )
115+ )
116+
84117 // *** Early exits ***
85118 // Don't use the proxy's IP, use the requester's for rate limiting
86119 // See https://expressjs.com/en/guide/behind-proxies.html
@@ -110,7 +143,6 @@ export default function (app) {
110143 app . set ( 'etag' , false ) // We will manage our own ETags if desired
111144 app . use ( compression ( ) )
112145 app . use ( disableCachingOnSafari )
113- app . use ( setFastlySurrogateKey )
114146 app . use ( catchBadAcceptLanguage )
115147
116148 // *** Config and context for redirects ***
@@ -136,31 +168,6 @@ export default function (app) {
136168 app . use ( haltOnDroppedConnection )
137169
138170 // *** Rendering, 2xx responses ***
139- // I largely ordered these by use frequency
140- // archivedEnterpriseVersionsAssets must come before static/assets
141- app . use (
142- asyncMiddleware (
143- instrument ( archivedEnterpriseVersionsAssets , './archived-enterprise-versions-assets' )
144- )
145- )
146- app . use (
147- '/assets' ,
148- express . static ( 'assets' , {
149- index : false ,
150- etag : false ,
151- lastModified : false ,
152- maxAge : '1 day' , // Relatively short in case we update images
153- } )
154- )
155- app . use (
156- '/public' ,
157- express . static ( 'data/graphql' , {
158- index : false ,
159- etag : false ,
160- lastModified : false ,
161- maxAge : '7 days' , // A bit longer since releases are more sparse
162- } )
163- )
164171 app . use ( '/events' , asyncMiddleware ( instrument ( events , './events' ) ) )
165172 app . use ( '/search' , asyncMiddleware ( instrument ( search , './search' ) ) )
166173
0 commit comments