ali-sdk / ali-oss

Aliyun OSS(Object Storage Service) JavaScript SDK for the Browser and Node.js
https://www.alibabacloud.com/help/doc-detail/52834.htm
MIT License
1.95k stars 576 forks source link

使用webpack打包后,出现跨域问题 #140

Closed rdshoep closed 8 years ago

rdshoep commented 8 years ago

新版本的http-browserify会将withCredentials默认设置为true,除非手动设置为false。

if (typeof params.withCredentials === 'undefined') {
        params.withCredentials = true;
    }

    try { xhr.withCredentials = params.withCredentials }
    catch (e) {}

导致测试环境下出现 XMLHttpRequest cannot load http://***.***.aliyuncs.com/pk1474962037953_84718. Response to preflight request doesn't pass access control check: A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://127.0.0.1:3000' is therefore not allowed access. The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute.

OSS后台是如何控制的?目前好像默认返回Access-Control-Allow-Origin:*

求指导.

rockuw commented 8 years ago

OSS Bucket设置中,可以指定allow origin: https://help.aliyun.com/document_detail/31903.html

rdshoep commented 8 years ago

@rockuw Got it, Thanks!

rdshoep commented 8 years ago

再请教一个问题:

如果将alioss一块儿打包之后会出现上面的问题,但是使用你们提供的cdn版本就没有问题。后台配置相同通,都设置为*。

rockuw commented 8 years ago

这个不太清楚了,有可能是新版本的http-browserify的问题?

rdshoep commented 8 years ago

应该不是,我追踪了一下http-browserify的版本,再很早期的版本就打开了这个默认参数(1.+版本都有)。

我通过withCredentials检索过你们的代码,没有发现默认设置为true的设置。所以想知道你们是如何配置的,在这个仓库中没有发现对http-browserify特殊处理。

rockuw commented 8 years ago

我们的配置都在 browser-build.js 中了,你可以研究一下。