【发布时间】:2020-08-25 09:08:36
【问题描述】:
是否可以在没有 CORS 代理的情况下直接在浏览器中从公共 GitHub 存储库下载 tarball?
fetch('https://api.github.com/repos/vadimkantorov/torchwav/tarball/master')
/*Refused to connect to 'https://api.github.com/repos/vadimkantorov/torchwav/tarball/master' because it violates the following Content Security Policy directive: "connect-src mc.admetrica.ru wss://webasr.voicetech.yandex.net mc.yandex.ru yandex.ru".
(anonymous) @ VM24:1
VM24:1 Refused to connect to 'https://api.github.com/repos/vadimkantorov/torchwav/tarball/master' because it violates the document's Content Security Policy.
(anonymous) @ VM24:1
Promise {<rejected>: TypeError: Failed to fetch
at <anonymous>:1:1}
VM24:1 Uncaught (in promise) TypeError: Failed to fetch
at <anonymous>:1:1
*/
fetch('https://github.com/vadimkantorov/torchwav/archive/master.tar.gz')
/*VM52:1 Refused to connect to 'https://github.com/vadimkantorov/torchwav/archive/master.tar.gz' because it violates the following Content Security Policy directive: "connect-src mc.admetrica.ru wss://webasr.voicetech.yandex.net mc.yandex.ru yandex.ru".
(anonymous) @ VM52:1
VM52:1 Refused to connect to 'https://github.com/vadimkantorov/torchwav/archive/master.tar.gz' because it violates the document's Content Security Policy.*/
【问题讨论】:
-
让“下载”链接访问您的节点服务器,该服务器获取 tarball,并将其发送回您的 UI。
-
这是一个有效的解决方案,CORS 代理也是如此,但我想知道是否还有其他方法。也许,GitHub 特定的?例如。可以通过 GitHub API 单独请求所有文件,但这会很慢并且会占用 API 配额...
标签: javascript github cors