question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

404s get cached and provided as 200

See original GitHub issue

Hi!

I followed the next.js ssr-caching example, so I’ve got a route like this:

server.get('/product/:handle', (req, res) => { const queryParams = { handle: req.params.handle }; const pagePath = '/product/' + req.params.handle'; return ssrCache({ req, res, pagePath, queryParams }); });

When a non-existent handle gets hit, the server responds with 404 but the second time it’s 200. How can I prevent this?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Kikobeatscommented, Feb 16, 2020

In the current implementation, you can avoid store a value into the cache if you return undefined or null: https://github.com/Kikobeats/cacheable-response/blob/master/index.js#L85

so, if in your code workflow you return one of these values under your 404 error, then it should be enough to don’t store it into the cache.

Can you confirm me that workflow works?

Read more comments on GitHub >

github_iconTop Results From Across the Web

404's in dynamic routes get cached and provided with status ...
Describe the issue​​ Following the ssr-caching example, get requests to dynamic routes that respond with a 404 status code get cached and ......
Read more >
404s being cached by service worker [#3015329] | Drupal.org
There should be a 404 for the missing image. Replace the missing file on the server; On the test browsing session, refresh the...
Read more >
How To Prevent Soft 404 Errors In Quick Cache - TechLogon
How to stop Quick Cache returning an incorrect 200 header response for a 404 (Page Not Found) error page – known as a...
Read more >
How to avoid caching 404 - Cloudflare Community
I don't know why the 404 caches are not expired after 3 minutes like the official document's statement. Maybe because I set the...
Read more >
How do I add no-cache headers to all 404 pages served by ...
Before Cloudflare, a re-request to the 404ed file would very quickly become 200 as rsync does its job. However, since Cloudflare caches all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found