I’ve got a Gatsby 5 website hosted on netfliy. Everything works great with SSG but I wanted to add a page with server side rendering.
If I add getServerData on a page, on local works great but when I deploy on netlify I get a 404 on that same page.
I tried to install gatsby-plugin-netlify but it still doesn’t work.
I read that the Essential Gatsby plugin was installed automatically but apparently it was not. Adding it in the netlify.toml file made it.
package = "@netlify/plugin-gatsby"
Error 404 went away, but then came error 500. It turned out I had to move the graphql query from outside the component from inside. This is the commit that made it.
(that page no longer exists too as it was one more experiment, I was in trial-and-error at that point)
That said, we can consider the issue here solved as SSR is kind of working now. Since we’re here, I think I have a problem with cache now but that would be a new topic, maybe I can open a new post here on the forum.
This is my getServerData but I see getVideos is called everytime, not sure what is wrong.
Maybe I understood it wrong, but I would have expected with this configuration (from the snippet in the previous reply) that the function getServerData is not executed again for 10 minutes after the first run.
Netlify doesn’t respect user-set stale-while revalidate, and you should most likely not set custom cache headers when using functions, as it could potentially break your site’s cache. Netlify provides On-Demand Builders that accept a custom revalidate time to provide a similar functionality.
However, since Gatsby doesn’t support revalidate-based regeneration (at least I could not find any such information), we currently do not generate any On Demand Builders for Gatsby like we do for Next.js.
As mentioned, SWR headers would not be respected and any custom cache control headers are not recommended (especially for server-side stuff), so currently you cannot set a timeout for the cache - the SSR will happen on every request.