Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
952 views
in Technique[技术] by (71.8m points)

digital ocean - Can't add http://localhost to DigitalOcean Spaces CORS Rules

Image Showing CORS Error

As you can see from the image is it not currently possible to add http://localhost as a CORS rule.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In order to fix this issue you must use a tool such as s3cmd. The easiest way to use this tool is by downloading the source. If you already have Python installed you can use the following commands to change DigitalOcean Spaces CORS configuration (requires python 2.7 or greater):

Note: You may also need to have Gpg4win installed.

First download the source from here and extract into any directory. Then run the following commands in that directory. You should also place your cors.xml config within this directory.

python s3cmd --configure

This is an example input for the config hosted on Amsterdam 3....

Access Key [YOUR_ACCESS_KEY]:
Secret Key [YOUR_SECRET_KEY]: 
S3 Endpoint [ams3.digitaloceanspaces.com]
DNS-style bucket+hostname:port template for accessing a bucket [%(bucket)s.ams3.digitaloceanspaces.com]:
Encryption password [password]:

python s3cmd ls - View all of your spaces

python s3cmd setcors cors.xml s3://your-space-name-here where cors.xml is a file in your working directory containing a standard cors configuration such as:

<CORSConfiguration>
 <CORSRule>
   <AllowedOrigin>http://localhost:4000</AllowedOrigin>

   <AllowedMethod>GET</AllowedMethod>
   <AllowedMethod>HEAD</AllowedMethod>

 </CORSRule>
</CORSConfiguration>

After running this final command you should now see in your DigitalOcean dashboard that your original CORS configuration has now been replaced with whatever configuration you saved to cors.xml


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...