github - GitHub Pages上的跨源资源共享

标签 github cors github-pages

有没有办法为 GitHub Pages 上托管的静态页面启用跨域资源共享 (CORS)允许 JavaScript 中的跨域请求?

例如,我们能否以某种方式指示 GH Pages 添加这些 HTTP 响应 header :

Access-Control-Allow-Origin:*  
Access-Control-Allow-Methods:GET,POST
Access-Control-Max-Age: 1000
Access-Control-Allow-Headers:*

在其 documentation 中找不到任何内容,还有这个...

...GitHub Pages does not support customer server configuration files such as .htaccess or .conf...

...听起来不太有希望 - 或者有办法吗?

最佳答案

编辑: 耶!看起来 GitHub Pages 现在支持 CORS:https://twitter.com/invisiblecomma/status/575219895308324864

这可以通过 curl 请求到enable-cors.org(托管在GitHub Pages上)来验证。运行此命令:curl -v enable-cors.org >/dev/null 返回 Access-Control-Allow-Origin: * header 。

GitHub Pages 上无法支持 CORS,尽管我很想看到此功能。我们主持http://enable-cors.org在 GitHub Pages 上,我们无法在网站本身上启用 CORS :)

<小时/>

更新

正如 @Styx 所指出的,GitHub 页面现在始终重定向到 HTTPS。因此,如果您想亲自确认是否允许所有来源,对于使用 GitHub 页面的特定站点,请尝试使用 curl-L (遵循所涉及的重定向) 。例如:

$ curl -vL square.github.io/okhttp 2>&1 | fgrep -i access-control-allow-origin

关于github - GitHub Pages上的跨源资源共享,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26416727/

相关文章:

javascript - 为什么我的页面没有加载到 Github 上?

angularjs - 无法在 'postMessage' : The target origin provided 'DOMWindow' ) does not match the recipient window's origin 上执行 ('https://outlook.office.com'

c# - Blazor 无法连接到 ASP.NET Core WebApi (CORS)

CSS 文件在 Jekyll 网站上无法正常工作

git - 如何从 gitlab/github 克隆我的所有存储库?

Github Pages主页删除顶部链接

github - 如何仅显示合并到默认分支后不会被 "Fix #123"提交消息关闭的问题?

spring - 在 Spring 上启用 CORS 访问 MongoDB 数据

github-pages - pages.github.com是否支持带有前缀的目录名。 (点)?

javascript - 如何让gh-pages找到bundle.js