How to add CORS to Digital Ocean app? And how to fix Spaces CORS issue?

I am hosting a Strapi application on the DO App platform and using a DO spaces to host images for it. I think I have updated the CORS policy for the Spaces bucket but I can’t work out how to add CORS for my actual app.

In Strapi, there is a CORS config which I have setup but not sure if DO adds its own.

A client that uses the app and the website it servers content to has been running into a CORS error - Access to XMLHttpRequest at ‘URL OF API’ from origin ‘WEBSITE’ has been blocked by CORS policy No ‘Access-Control-Allow-Origin’ header is present on the resource.

Any help with these issues would be grand.

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
May 12, 2023

Hi there,

In addition to configuring the CORS settings in your Spaces, I would recommend two additional things:

  • Configure the CORS settings in your Strapi config/middleware.js file. In the origin field, you list the domains that you want to allow. The methods field lists the HTTP methods that your server will allow. The headers field lists the request headers that your server will allow.
  • Also, in addition to that, configure the CORS policy in your DigitalOcean App Platform, first g to, click on your app, click Settings, and click the resource whose CORS policies you would like to edit. Under the CORS Policy heading, you will be able to add an origin and specify which match type to use.

If you are still hitting the error, feel free to share the exact error message that you are seeing in your web console here.



Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel