amazon-web-services - CORS 从 S3 静态网站访问端点时出错

我正在从 aws s3 静态网站调用我的 rest 端点并低于 CORS 错误

Access to fetch at 'http://[my-public-ip]:5225/user/1' 
from origin 'http://[my-bucket].s3-website-us-east-1.amazonaws.com' 
has been blocked by CORS policy: The request client is not a secure context 
and the resource is in more-private address space `private`.

我的springboot中有以下代码允许cors,我也尝试了各种其他组合,如allowedOrigins、allowedMethods,但它们都不起作用

@Override
public void addCorsMappings( CorsRegistry registry ) {
  registry.addMapping( "/**" );
}

我也尝试在 s3 中添加 cors 设置

[
    {
        "AllowedHeaders": [
            "Authorization"
        ],
        "AllowedMethods": [
            "GET",
            "HEAD"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": [
            "Access-Control-Allow-Origin"
        ]
    }
]

我错过了什么吗?

回答1

我找到了解决方案。问题仅在于 chrome 浏览器。 S3 静态端点在 http 上,springboot 后端应用程序在 https 上。

我为我的 s3 静态网站创建了一个云端分发版,现在因为两者都在 https 上,所以我没有收到错误消息。

相似文章

随机推荐

最新文章