Skip to content

Commit f174ed6

Browse files
committed
chore: added some logging temporarily
1 parent 472ed1d commit f174ed6

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

packages/runtime/src/templates/getHandler.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Mutable<T> = {
2525
}
2626

2727
// We return a function and then call `toString()` on it to serialise it as the launcher function
28+
/* eslint-disable max-lines-per-function */
2829
// eslint-disable-next-line max-params
2930
const makeHandler = (conf: NextConfig, app, pageRoot, staticManifest: Array<[string, string]> = [], mode = 'ssr') => {
3031
// 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
9495
}
9596

9697
return async function handler(event: HandlerEvent, context: HandlerContext) {
98+
console.log('handler args', { event, context })
9799
let requestMode = mode
98100
// Ensure that paths are encoded - but don't double-encode them
99101
event.path = new URL(event.rawUrl).pathname
@@ -123,19 +125,32 @@ const makeHandler = (conf: NextConfig, app, pageRoot, staticManifest: Array<[str
123125
// Sending SWR headers causes undefined behaviour with the Netlify CDN
124126
const cacheHeader = multiValueHeaders['cache-control']?.[0]
125127

128+
console.log('stale-while-revalidate?', cacheHeader?.includes('stale-while-revalidate'))
129+
126130
if (cacheHeader?.includes('stale-while-revalidate')) {
127131
if (requestMode === 'odb') {
132+
console.log('request mode is odb')
128133
const ttl = getMaxAge(cacheHeader)
134+
console.log('ttl = getMaxAge(cacheHeader)', ttl)
129135
// 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)
130137
if (ttl > 0 && ttl < ONE_YEAR_IN_SECONDS) {
131138
// ODBs currently have a minimum TTL of 60 seconds
132139
result.ttl = Math.max(ttl, 60)
140+
console.log('ttl updated to', result.ttl)
133141
}
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)) {
136148
// Only cache for 60s if default TTL provided
137149
result.ttl = 60
150+
console.log('default TTL provided so update ttl to 60 seconds', result.ttl)
138151
}
152+
153+
console.log('result.ttl', result.ttl)
139154
if (result.ttl > 0) {
140155
requestMode = `odb ttl=${result.ttl}`
141156
}
@@ -153,6 +168,7 @@ const makeHandler = (conf: NextConfig, app, pageRoot, staticManifest: Array<[str
153168
}
154169
}
155170
}
171+
/* eslint-enable max-lines-per-function */
156172

157173
export const getHandler = ({ isODB = false, publishDir = '../../../.next', appDir = '../../..' }): string =>
158174
// This is a string, but if you have the right editor plugin it should format as js

0 commit comments

Comments
 (0)