下面是我所做的:我使用Angular 2创建了前端,并使用Spring boot创建了后端代码。然后在我的前端代码中,我使用EC2地址(在前端)硬编码我的api地址,并在Spring boot的Filter类中硬编码我的前端地址( S3地址),以消除CORS问题。
然后在我的前端我运行ng build --prod来获取部署静态文件,在我的后端我运行mvn package来获取jar文件。上传jar文件到EC2实例,后端part启动成功。
现在将所有静态文件上传到S3存储中,并运行S3域,我得到了以下错误:
Failed to load ec2-35-182-225-61.ca-central-1.compute.amazonaws.com:8080/api/refresh: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. 有没有使用S3和EC2连接前端和后端的教程?
编辑:在我通过trichetriche的答案在S3部件上添加CORS后,我得到了新的错误
main.e4936af900574d09c368.bundle.js:1 ERROR DOMException: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL
at http://cloud.eatr.com.s3-website.ca-central-1.amazonaws.com/polyfills.b3f1cff0521ef8205be4.bundle.js:1:56874
at XMLHttpRequest.o.(anonymous function) [as open] (http://cloud.eatr.com.s3-website.ca-central-1.amazonaws.com/polyfills.b3f1cff0521ef8205be4.bundle.js:1:20687)
at t._subscribe (http://cloud.eatr.com.s3-website.ca-central-1.amazonaws.com/main.e4936af900574d09c368.bundle.js:1:424047)
at t._trySubscribe (http://cloud.eatr.com.s3-website.ca-central-1.amazonaws.com/main.e4936af900574d09c368.bundle.js:1:7030)
at t.subscribe (http://cloud.eatr.com.s3-website.ca-central-1.amazonaws.com/main.e4936af900574d09c368.bundle.js:1:6859)
at e.a (http://cloud.eatr.com.s3-website.ca-central-1.amazonaws.com/main.e4936af900574d09c368.bundle.js:1:745892)
at e._innerSub (http://cloud.eatr.com.s3-website.ca-central-1.amazonaws.com/main.e4936af900574d09c368.bundle.js:1:748287)
at e._tryNext (http://cloud.eatr.com.s3-website.ca-central-1.amazonaws.com/main.e4936af900574d09c368.bundle.js:1:748211)
at e._next (http://cloud.eatr.com.s3-website.ca-central-1.amazonaws.com/main.e4936af900574d09c368.bundle.js:1:748034)
at e.next (http://cloud.eatr.com.s3-website.ca-central-1.amazonaws.com/main.e4936af900574d09c368.bundle.js:1:9365)发布于 2018-01-16 00:08:21
你的S3的CORS设置好了吗?
在您的S3配置中,您应该添加以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>它位于CORS Configuration中的Permissions选项卡下
(一旦你完成了测试,记得将原点设置为你的域)
https://stackoverflow.com/questions/48266608
复制相似问题