@@ -25,6 +25,7 @@ type Mutable<T> = {
25
25
}
26
26
27
27
// We return a function and then call `toString()` on it to serialise it as the launcher function
28
+ /* eslint-disable max-lines-per-function */
28
29
// eslint-disable-next-line max-params
29
30
const makeHandler = ( conf : NextConfig , app , pageRoot , staticManifest : Array < [ string , string ] > = [ ] , mode = 'ssr' ) => {
30
31
// Change working directory into the site root, unless using Nx, which moves the
@@ -94,6 +95,7 @@ const makeHandler = (conf: NextConfig, app, pageRoot, staticManifest: Array<[str
94
95
}
95
96
96
97
return async function handler ( event : HandlerEvent , context : HandlerContext ) {
98
+ console . log ( 'handler args' , { event, context } )
97
99
let requestMode = mode
98
100
// Ensure that paths are encoded - but don't double-encode them
99
101
event . path = new URL ( event . rawUrl ) . pathname
@@ -123,19 +125,32 @@ const makeHandler = (conf: NextConfig, app, pageRoot, staticManifest: Array<[str
123
125
// Sending SWR headers causes undefined behaviour with the Netlify CDN
124
126
const cacheHeader = multiValueHeaders [ 'cache-control' ] ?. [ 0 ]
125
127
128
+ console . log ( 'stale-while-revalidate?' , cacheHeader ?. includes ( 'stale-while-revalidate' ) )
129
+
126
130
if ( cacheHeader ?. includes ( 'stale-while-revalidate' ) ) {
127
131
if ( requestMode === 'odb' ) {
132
+ console . log ( 'request mode is odb' )
128
133
const ttl = getMaxAge ( cacheHeader )
134
+ console . log ( 'ttl = getMaxAge(cacheHeader)' , ttl )
129
135
// Long-expiry TTL is basically no TTL, so we'll skip it
136
+ console . log ( 'ttl > ONE_YEAR_IN_SECONDS' , ttl > ONE_YEAR_IN_SECONDS )
130
137
if ( ttl > 0 && ttl < ONE_YEAR_IN_SECONDS ) {
131
138
// ODBs currently have a minimum TTL of 60 seconds
132
139
result . ttl = Math . max ( ttl , 60 )
140
+ console . log ( 'ttl updated to' , result . ttl )
133
141
}
134
- const ephemeralCodes = [ 301 , 302 , 307 , 308 , 404 ]
135
- if ( ttl === ONE_YEAR_IN_SECONDS && ephemeralCodes . includes ( result . statusCode ) ) {
142
+ const ephemeralCodes = new Set ( [ 301 , 302 , 307 , 308 , 404 ] )
143
+ console . log (
144
+ 'ttl === ONE_YEAR_IN_SECONDS && ephemeralCodes.includes(result.statusCode)' ,
145
+ ttl === ONE_YEAR_IN_SECONDS && ephemeralCodes . has ( result . statusCode ) ,
146
+ )
147
+ if ( ttl === ONE_YEAR_IN_SECONDS && ephemeralCodes . has ( result . statusCode ) ) {
136
148
// Only cache for 60s if default TTL provided
137
149
result . ttl = 60
150
+ console . log ( 'default TTL provided so update ttl to 60 seconds' , result . ttl )
138
151
}
152
+
153
+ console . log ( 'result.ttl' , result . ttl )
139
154
if ( result . ttl > 0 ) {
140
155
requestMode = `odb ttl=${ result . ttl } `
141
156
}
@@ -153,6 +168,7 @@ const makeHandler = (conf: NextConfig, app, pageRoot, staticManifest: Array<[str
153
168
}
154
169
}
155
170
}
171
+ /* eslint-enable max-lines-per-function */
156
172
157
173
export const getHandler = ( { isODB = false , publishDir = '../../../.next' , appDir = '../../..' } ) : string =>
158
174
// This is a string, but if you have the right editor plugin it should format as js
0 commit comments