rudixlab
By:
rudixlab

CORS spaces public

December 2, 2017 124 views
Object Storage

Greetings, I am new to spaces and pretty much excited what DO is accomplishing .
Setup and upload was easy using node.js aws-sdk,
I have few large JSON files which I want to serve API-Like for the client
Unfortunately I don't know how to setup CORS for such application
Please advice
Thanks!

2 Answers
johngannon MOD December 8, 2017
Accepted Answer

@rudixlab we just added support for CORS configuration via the UI this week. You can find it on the 'Settings' tab of any Space. Hope this helps!

  • Hello. This does not seem to work. There are still no Allow headers returned

    • @ilguzin can you email me your config (the XML you used, or screengrab of UI) plus debugging output from curl or the browser? jgannon at do dot co

      • It's weird, but looks like now it works. There probably was a delay before the changes propagated (at least more then one hour). Although i'm not sure which of the approaches worked for me: the AWS SDK based that is @rudixlab suggested or DigitalOcean Settings UI, i tried both. At any rate thanks for quick response.

seems like I fixed it using AWS sdk with node.js

 const thisConfig = {
    AllowedMethods: ['GET', 'POST', 'PUT', 'HEAD'],
    AllowedOrigins: ['*'],
    ExposeHeaders: [],
    MaxAgeSeconds: 3000,
  };

  const corsRules = new Array(thisConfig);
  const corsParams = {
    Bucket: 'bucket-name',
    CORSConfiguration: { CORSRules: corsRules },
  };
  // set the new CORS configuration on the selected bucket
  s3.putBucketCors(corsParams, (err, data) => {
    if (err) {
      console.log('Error', err);
    } else {
      console.log('Success', data);
    }
  });
}
Have another answer? Share your knowledge.