Question

Rebuild static website on content change

Posted June 16, 2021 179 views
DigitalOcean App PlatformStrapi

I have a Strapi CMS and Gridsome static website as 2 components on App platform. Is there a way to rebuild the static website on change using Strapi’s webhooks?

edited by kamaln7

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi there @stfnnklc,

It looks like that a similar question has been discussed previously here. What you could do is use the DigitalOcean API to force a rebuild for your application.

You would need to make a POST request to the /v2/apps/<app_id>/deployments route and pass a JSON document for the body. You can set the force_build option in it like so:

curl \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer TOKEN" \
    "https://api.digitalocean.com/v2/apps/<app_id>/deployments" \
    -XPOST \
    -d '{"force_build": true}'

Hope that this helps!
Regards,
Bobby

  • Thanks @bobbyiliev,

    It helps, but I’m not sure how to pass the body. Strapi only accepts headers.
    As I understand it, a workaround would be to manually add a POST request on any create, delete and update of any of my collection and single types, but that doesn’t seem like a nice solution since I have many types.
    Another one would be to make a small node server that accepts a request from Strapi, and then makes a proper POST request to DO.

    What would you suggest?

    Thanks again,
    Stefan

    • Hi there @stfnnklc,

      I think that the idea with the small Node service sounds good. That way you will be able to pass the request to the service and then it would do the API call to the DigitalOcean API to force the redeploy.

      Let me know how this goes!

      • @bobbyiliev

        I managed to trigger a build, but it was skipped since the code didn’t change. Also I would like to rebuild only the front-end component of the app, not everything. Not sure if this is possible…

        • Hi there,

          As of the time being when using force_build, it will rebuild all components. It is being considered adding an option that lets users only rebuild a specific component but it’s not possible yet.

          Regarding the skipped build, it sounds like that the API request body might not be passed correctly. When you have the '{"force_build": true}' payload the build will be forced even when there are no changes.

          You could test it with the curl command from above.

          Also, feel free to share the code snippet responsible for the request here.

          Regards,
          Bobby