Because as Kian mentioned the SPA does
Because as Kian mentioned the SPA does not have a server so the cors approach would never really work as the 'client' can't really respond (if i got it correctly)
7 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Oh, so I can setup cors one time and then the bucket keeps those settings?
How should I do that?
So its a matter of configuring the bucket then?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I have set the bucket cors via
aws s3api put-bucket-cors --bucket <bucketName> --cors-configuration file://cors.json --endpoint-url https://<accountid>.r2.cloudflarestorage.com
and just checked via aws s3api get-bucket-cors --bucket <bucketName> --endpoint-url https://<accountid>.r2.cloudflarestorage.com
I get back
as the defined bucket-cors
and yet still get the ...from origin 'http://localhost:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Any idea on how to address this?
nevermind. Silly mistake on my end. changed localhost:5173
into http:localhost:5173
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
it didn't work without it
and now everything is working as I would expect it to!!
Thank you a lot for you extremely useful guidance!!!
Perhaps a useful thing to add to the docs currently (as the UI is not yet working)
- Add this to
package.json
inside the scripts
- Replace <BucketName>
with your R2 bucket name
- Replace <UserID>
with your cloudflare User ID
- Create a cors.json
file with your desired CORS
settings
- To apply the CORS
rules do:
- npm run cors:set
(To set the CORS rules)
- npm run cors:get
(To check if it applied correctly)Unknown User•2y ago
Message Not Public
Sign In & Join Server To View