Ant-design-pro: 从 mock 直接切换到服务端请求?

Created on 8 Mar 2018  ·  4Comments  ·  Source: ant-design/ant-design-pro

从 mock 直接切换到服务端请求#
通常来讲只要 mock 的接口和真实的服务端接口保持一致,那么只需要重定向 mock 到对应的服务端接口即可。
// .roadhogrc.mock.js
export default {
'GET /api/(.*)': 'https://your.server.com/api/',
};
这样你浏览器里这样的接口 http://localhost:8001/api/applications 会被反向代理到 https://your.server.com/api/applications 下。

按照文档进行了配置,但是请求还是走的 localhost,没有反向代理呢

Request URL:http://localhost:8000/api/rule?no=5555
Request Method:GET
Status Code:200 OK
Remote Address:127.0.0.1:8000
Referrer Policy:no-referrer-when-downgrade

Most helpful comment

image
楼上正解

All 4 comments

客户端发请求到代理服务器,显示这种请求头是正常的。关键是your.server.com有没有收到请求,这才是证明是否代理成功。可以这样理解这个过程:

请求过程:client -> proxy -> target
响应过程:client <- proxy <- target

提醒一点,由于mock依赖的express-http-proxy在post请求上有一些缺陷,建议使用roadhog的proxy配置项来实现proxy。

image
楼上正解

thanks!

@wuyongdec 我的设置了怎么还是不对呢?

Was this page helpful?
0 / 5 - 0 ratings