Report this

What is the reason for this report?

Rebuild static website on content change

Posted on June 16, 2021

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?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.
0

Accepted 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

With the new DO serverless functions you could receive the Strapi webhook request and then trigger the deployment.

If someone want to use the new DO serverless functions:

function main(args) {
  const https = require('https');
  const url = 'https://api.digitalocean.com/v2/apps/fda88e43-3e89-46e1-bbac-d4c25993fda6/deployments';
  const data = JSON.stringify({"force_build": true});

  const options = {
    host: 'api.digitalocean.com',
    port: 443,
    path: '/v2/apps/<APP_ID>/deployments',
    method: 'POST',
    headers: {
      'Authorization': 'Bearer <TOKEN>',
      'Content-Type': 'application/json',
      'Content-Length': data.length
    }
  };

  var req = https.request(options, function(res) {
    console.log("statusCode: ", res.statusCode);
    console.log("headers: ", res.headers);

    res.on('data', function(d) {
      process.stdout.write(d);
    });
  });

  req.write(data); // Write the request body
  req.end();
}

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.