How do I enable preview option in strapi(backend)/gatsby(frontend) without using gatsby cloud?
I have used gatsby cloud and it perfectly works fine. But I am looking to implement this feature on my own as gatby cloud for enterprise is expensive.
How do I enable preview option in strapi(backend)/gatsby(frontend) without using gatsby cloud?
I have used gatsby cloud and it perfectly works fine. But I am looking to implement this feature on my own as gatby cloud for enterprise is expensive.
The idea that is relying upon your question is somewhere complex and requires a lot of implementations.
Literally, you need to use a webhook to trigger a develop/build command in your environment. This is possible in Strapi 3.x.x as it is shown in their official documentation but is still being a beta feature.
Some CMS (like DatoCMS does) exposes an option to reload the data provided in every change of content but with Strapi, there's no such option, at least not well documented in Gatsby's documentation about Strapi.
Everything is handled by Gatsby Cloud (that's why is expensive) but, another approach or workaround it may fit you is to use the localhost:8000/___refresh (it will only work for develop command):
From Gatsby documentation about environment variables:
If set to true, this will expose a
/__refreshwebhook that is able to receivePOSTrequests to refresh the sourced content. This exposed webhook can be triggered whenever remote data changes, which means you can update your data without re-launching the development server.You can trigger this endpoint locally, for example, on Unix-based operating systems (like Ubuntu and MacOS) using
curl -X POST http://localhost:8000/__refresh
So basically, you need to set an environment variable to true, and every request done to localhost:8000/___refresh will load the content again. To achieve it, first, you need to change your develop command to (in your package.json):
"develop": "ENABLE_GATSBY_REFRESH_ENDPOINT=true gatsby develop",
Note: you'll need to run npm run develop/ yarn develop from now on
Then, every request to localhost:8000/___refresh will reload your data. You can do this simply with an onClick button function or whatever.