Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ function saveToCache(req, page: any) {
const key = getCacheKey(req);
// Avoid caching "/reload/[random]" paths (these are hard refreshes after logout)
if (key.startsWith('/reload')) { return; }
// Avoid caching non-successful responses (status code different from 2XX). Without this, the
// rendered 404 not-found page gets stored in the cache and is later replayed via res.send()
// as HTTP 200 - turning a correct 404 into a soft-404. (matches dtq-dev cache behaviour)
if (hasNotSucceeded(req.res.statusCode)) { return; }

// If bot cache is enabled, save it to that cache if it doesn't exist or is expired
// (NOTE: has() will return false if page is expired in cache)
Expand All @@ -459,6 +463,15 @@ function saveToCache(req, page: any) {
}
}

/**
* Check if status code is different from 2XX
* @param statusCode HTTP status code of the current response
*/
function hasNotSucceeded(statusCode) {
const rgx = new RegExp(/^20+/);
return !rgx.test(statusCode);
}
Comment on lines +470 to +473

/**
* Whether a user is authenticated or not
*/
Expand Down
Loading