meteorlxy / vssue

:mailbox: A Vue-powered Issue-based Comment Plugin
https://vssue.js.org
MIT License
769 stars 105 forks source link

[Question] has been blocked by CORS policy #84

Closed wangtager closed 4 years ago

wangtager commented 4 years ago

Environment

配置如下: ['@vssue/vuepress-plugin-vssue', { locale: 'zh', platform: 'github', owner: 'xx', repo: 'xx', clientId: 'xx', clientSecret: 'xx', proxy: url => https://api.github.com?target=${url} }]

vuepress 在本地运行没有问题,发布后报错,cors 的错误: has been blocked by CORS policy: Request header field accept is not allowed by Access-Control-Allow-Headers in preflight response.

项目发布后不能提交评论、也获取不到评论信息。(但在本地运行一切正常)

meteorlxy commented 4 years ago

请提供复现仓库和网页链接

meteorlxy commented 4 years ago

proxy: url => https://api.github.com?target=${url}

这个配置是什么情况?

wangtager commented 4 years ago

复现仓库: https://github.com/wangtager/blog 网页链接: https://wangtager.github.io/blog/sublime/sublime.html

获取评论信息的时候, 发送了option请求且不通过导致的,不知道为什么会这样。另外两个https://api.github.com接口的get请求是正常的

wangtager commented 4 years ago

proxy属性是官网上https://vssue.js.org/zh/options/#proxy 提供的配置,说是在GitHub平台不能直接调用GitHub api 。没加这个属性时,把项目发布到github上后,GitHub api 全部调用失败了

meteorlxy commented 4 years ago

这个属性也不是这么加的啊,除非你有自己的 cors 代理

meteorlxy commented 4 years ago

你这里失败的请求是因为多了一个这个,有点奇怪

image

wangtager commented 4 years ago

proxy 现在是去掉的,结果也是一样的。会不会和clientSecret明文 提交到了github上有关系了?

meteorlxy commented 4 years ago

没有关系,只和这里莫名其妙多一个 accept 有关系

delphixp commented 4 years ago

我的 Gitea 部署在局域网中,同时也在局域网中建一个 proxy server ,仍然被 CORS 拦截。。

  <script>
    new Vue({
      el: '#vssue',

      data: {
        title: 'Vssue Demo',

        options: {
          baseURL: 'http://x.x.x.x:8080',
          proxy: url => `http://localhost:8001/${url}`,
          owner: 'xxx',
          repo: 'xxx',
          clientId: 'xxx',
          clientSecret: 'xxx',
        },
      },

      template: `<vssue :title="title" :options="options"></vssue>`,
    })
  </script>

localhost:8001 ,就是本地跑的 cors-anywhere

成功拿到了 access_token,但是卡在 getUser(..) 这一步。。 768170500


另外,有没有可能将 UI 独立成一个组件,而 comment 可以从任何一个地方得到?

谢谢!

meteorlxy commented 4 years ago

@delphixp Gitea 的话和上面提到的 GitHub 的情况应该还不太一样,可以单独提供一下复现仓库和链接么。

现在 comment API 就是和组件分开的,@vssue/api-xxxxx 这些包就是

WuLianN commented 4 years ago

@meteorlxy 大佬,上面的问题有解决方案吗?我也遇到这样的问题,github能登录,能创建issue,不能评论,也不能获取评论。请求头多了个 Accept: [object Object]

meteorlxy commented 4 years ago

@WuLianN 难道是最近chrome有了什么更新。。麻烦提供一下复现仓库

WuLianN commented 4 years ago

复现仓库:https://github.com/WuLianN/blog 网页链接:https://bearcub.club

meteorlxy commented 4 years ago

基本确定了是 axios 0.19 + 版本的问题,vssue 仓库目前用的 axios 0.18 所以没事

meteorlxy commented 4 years ago

@WuLianN 不要手动指定 axios 0.19 版本就好了。后面可能会考虑使用原生 fetch 代替 axios