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

如何跨域? #50

Open
yinsang opened this issue Aug 9, 2017 · 2 comments
Open

如何跨域? #50

yinsang opened this issue Aug 9, 2017 · 2 comments

Comments

@yinsang
Copy link

yinsang commented Aug 9, 2017

我java后台是在本地跑的,返回一个json。localhost:8080
我把react-antd-admin设置为localhost:9090,想访问localhost:8080/bpm/pi时。
1,我在webpack.config.js中加入proxy怎么代理不过去?还是显示在localhost:9090/bpm/pi;
2,为什么我在config.js的api中修改host,能跨域到localhost:8080,但是返回:
XMLHttpRequest cannot load http://localhost:8080/bpm/pi. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9090' is therefore not allowed access.
这个项目上线的话是不需要跨域的,所以不能修改java代码。我改怎么改?

@jiangxy
Copy link
Owner

jiangxy commented Aug 10, 2017

对于这种情况,暂时没什么好办法😓

  1. webpack.config.js中的proxy配置,不是很了解。。
  2. 通过修改config.js中的host,确实能实现跨域的,但需要后端接口支持。我们一般的做法是将后端接口的跨域做成可配置项,只在测试/开发时开启。或者使用使用一些白名单机制之类的。

这个我再想想,看下有啥办法能简化下开发

@super-ai
Copy link

直接在webpack中配置 非常简单

devServer: {
    "proxy": {
      "/login": {
        "target": "http://localhost:8080",
      },
      "/api/*": {
        "target": "http://localhost:8080",
      }
    }
  }

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

3 participants