Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

跨域请求使用 resCors 的问题 #271

Closed
zarkin404 opened this issue Mar 9, 2019 · 5 comments
Closed

跨域请求使用 resCors 的问题 #271

zarkin404 opened this issue Mar 9, 2019 · 5 comments

Comments

@zarkin404
Copy link

zarkin404 commented Mar 9, 2019

为了方便前端开发,项目直接连线上测试库进行调试。使用的是 Axios 进行请求,按照 文档 里添加了两条属性到 keys 里,结果发现 header 并非自己所要的 response 字段:

origin: *
headers: *

当前的响应头部:

access-control-allow-origin: *
access-control-expose-headers: *

期望的响应头部:

access-control-allow-origin: *
access-control-allow-headers: *

因为不能设置 ,所以 Chrome 一直在 OPTION 阶段就中止了请求了:

Access to XMLHttpRequest at 'http://[ONLINE_DEV_SERVER]' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field x-requested-with is not allowed by Access-Control-Allow-Headers in preflight response.

请问大大有什么解决方法,谢谢了!

@zarkin404
Copy link
Author

先用 Chrome 插件 Allow CORS 顶了一下,也挺方便

@avwo avwo closed this as completed in fb81060 Mar 9, 2019
@avwo
Copy link
Owner

avwo commented Mar 9, 2019

是个bug,已经fix,更新下版本并重启:

npm i -g whistle --registry=https://registry.npm.taobao.org
w2 restart

配如下规则的效果:

``` test-cors.json
headers: *
origin: *
```
www.test.com/xxx resCors://{cors.json} file://(test)

image
image

@avwo avwo reopened this Mar 9, 2019
@zarkin404
Copy link
Author

image

已经可以用了,多谢大佬

@codeskyblue
Copy link

不明白我这边操作OPTIONS请求直接返回了403

image

最后只能这样配置规则,强求改status code,不知道这算不算是个bug

test.com resCors://enable 127.0.0.1:7001
test.com includeFilter://m:options resCors://{cors} statusCode://200

@Sdky
Copy link

Sdky commented Aug 11, 2023

我这边也是 OPTIONS 请求返回了 403,提示:Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
另外还要调整下规则顺序才可以

test.com includeFilter://m:options resCors://{cors} statusCode://200
test.com resCors://enable 127.0.0.1:7001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants