Unverified Commit 72a461f9 authored by Fabian Mastenbroek's avatar Fabian Mastenbroek Committed by GitHub

Do not cache 404 SSR responses (#10596)

This change updates the _ssr-caching_ to not cache the response when a
404 status code has been returned.
parent 9fdd344c
...@@ -10,9 +10,18 @@ const handle = app.getRequestHandler() ...@@ -10,9 +10,18 @@ const handle = app.getRequestHandler()
const ssrCache = cacheableResponse({ const ssrCache = cacheableResponse({
ttl: 1000 * 60 * 60, // 1hour ttl: 1000 * 60 * 60, // 1hour
get: async ({ req, res, pagePath, queryParams }) => ({ get: async ({ req, res, pagePath, queryParams }) => {
data: await app.renderToHTML(req, res, pagePath, queryParams), const data = await app.renderToHTML(req, res, pagePath, queryParams)
}),
// Add here custom logic for when you do not want to cache the page, for
// example when the page returns a 404 status code:
if (res.statusCode === 404) {
res.end(data)
return
}
return { data }
},
send: ({ data, res }) => res.send(data), send: ({ data, res }) => res.send(data),
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment