Last active
October 4, 2022 17:45
-
-
Save mikeesto/a702290925d90ee32b550a8981a657d2 to your computer and use it in GitHub Desktop.
Revisions
-
mikeesto revised this gist
Oct 3, 2022 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,12 @@ import aws from "aws-sdk"; const s3 = new aws.S3({ endpoint: `https://${process.env.CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com`, accessKeyId: process.env.CLOUDFLARE_ACCESS_KEY, secretAccessKey: process.env.CLOUDFLARE_SECRET_ACCESS_KEY, signatureVersion: "v4", }); const config = { AllowedHeaders: ["content-type"], // This seems to be necessary! Not including it gives errors. Putting it as * still gives CORS errors AllowedMethods: ["PUT"], -
mikeesto created this gist
Oct 3, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ const config = { AllowedHeaders: ["content-type"], // This seems to be necessary! Not including it gives errors. Putting it as * still gives CORS errors AllowedMethods: ["PUT"], AllowedOrigins: ["*"], }; const bucketParams = { Bucket: process.env.CLOUDFLARE_BUCKET_NAME, CORSConfiguration: { CORSRules: new Array(config) }, }; s3.putBucketCors(bucketParams, function (err, data) { if (err) { console.log("Error", err); } else if (data) { console.log("Success", JSON.stringify(data.CORSRules)); } });