To configure CORS on DigitalOcean Spaces and make it publicly accessible, you can set up permissions through the DigitalOcean control panel or use the DigitalOcean CLI. Here’s how to configure it:
1. Enable Public Access
To make your Space public:
- Go to the DigitalOcean Control Panel and navigate to Spaces.
- Select the Space you want to make public.
- Click on Settings.
- In the Permissions section, set File Listing to “Public.”
- Confirm by clicking Save.
This will make all objects in the Space accessible via a public URL.
2. Configure CORS Settings
You can define CORS rules directly in the Space’s settings:
- Go to Settings for your Space.
- Scroll down to CORS Configuration and click Edit CORS.
- Define the CORS configuration rules in JSON format. Here’s an example configuration to allow cross-origin access from any origin:
[
{
"AllowedHeaders": ["*"],
"AllowedMethods": ["GET", "POST", "HEAD"],
"AllowedOrigins": ["*"],
"ExposeHeaders": [],
"MaxAgeSeconds": 3000
}
]
- AllowedHeaders: Specify headers allowed in requests. Use
"*"
to allow all headers. - AllowedMethods: Define HTTP methods like
GET
,POST
,HEAD
. - AllowedOrigins: Use
"*"
to allow requests from any origin, or specify specific domains. - ExposeHeaders: Specify headers exposed to the client.
- MaxAgeSeconds: Defines how long the browser caches the CORS response.
- AllowedHeaders: Specify headers allowed in requests. Use
- Click Save to apply your CORS settings.
Now, your DigitalOcean Space will allow public access and permit cross-origin requests.
That’s it.
Happy Sngine 🙂
Buy Sngine or Extend your support: https://bit.ly/BuySngine