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

Created on 30 Nov 2017  ·  16Comments  ·  Source: ant-design/ant-design-pro

roadlog运行在本地8001端口
在本地开了REST服务,端口是3007
怎么将service中的请求指向REST服务呢?
比如service中的注册接口:
image
在修改了.roadhogrc或修改.roadhogrc.mock.js之后都没有效果
.roadhogrc:
image
.roadhogrc.mock.js
image

修改后请求没有指向3007端口,还是指向的8001:
image

Most helpful comment

可以直接在 .roadhogrc上加

"proxy": {
    "/api": {
      "target": "http://localhost:5000/api",
      "changeOrigin": true,
      "pathRewrite": { "^/api" : "" }
    }
  }

All 16 comments

可以直接在 .roadhogrc上加

"proxy": {
    "/api": {
      "target": "http://localhost:5000/api",
      "changeOrigin": true,
      "pathRewrite": { "^/api" : "" }
    }
  }

@muhawo 这个是个 bug,你升级下 roadhog-api-doc0.3.3

@nikogu 你头像的妹子是谁?

@nikogu 升级到0.3.3也没用,还是跟之前一样,roadhog-api-doc会影响到这个问题?

@nikogu 已升级,问题依然存在。

原来是bug我还提问题了

我也遇到了。。@nikogu

@muhawo 你这个问题搞定没,你用 chrome 网络工具调一下,看看请求头和返回体是什么

@adwerrdroadhog-api-doc 版本用的 0.3.3 吗?

现在好像是可以了 但我还没搞明白是怎么好的 搞明白了再回来说一下吧

@nikogu

Fixed in https://github.com/ant-design/ant-design-pro-site/commit/504a28a0d74e2e6ebaa193d247ab5f683dbeecc9


原来的文档是有问题的。如果你这么写:

'GET /api/*': 'http://your.server.com/api/',

那么 http://localhost:8001/api/xxx 会被转发到 http://your.server.com/api/api/xxx ,实际上是把前面的路径拼到后面的路径上。

需要改成下面这样:

'GET /api/(.*)': 'http://your.server.com/api/',

或者

'GET /api/*': 'http://your.server.com/',

这样 http://localhost:8001/api/xxx 会被转发到 http://your.server.com/api/xxx

更多信息:https://segmentfault.com/q/1010000012511821/a-1020000012522260

const noProxy = (process.env.NO_PROXY === 'true');
'GET /api/currentUser': {

$desc: "获取当前用户接口",
$params: {
pageSize: {
desc: '分页',
exp: 2,
},
},
$body: {
name: 'Serati Ma',
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png',
userid: '00000001',
notifyCount: 12,
},
},
...
export default (noProxy
? { "/*": "http://test.servcer.com" }
: delay(proxy, 1000));

这样配置后请求还是发送到localhost:8080该如何配置

const noProxy = true;
'GET /api/currentUser': {

$desc: "获取当前用户接口",
$params: {
pageSize: {
desc: '分页',
exp: 2,
},
},
$body: {
name: 'Serati Ma',
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png',
userid: '00000001',
notifyCount: 12,
},
},
...
export default (noProxy
? { "/*": "http://test.servcer.com" }
: delay(proxy, 1000));

这样配置后请求还是发送到localhost:8080如何修改

代理有问题

我的配置
//export default noProxy ?{}:
//  delay(proxy, 500);
export default {
  '/': 'http://localhost:8085/',
};

export async function login(params) {
  return request(`/login?username=${params.username}&password=${params.password}`);
}

访问报了400错误

export default noProxy ? {"/*": "http://192.168.6.88"} : delay(proxy, 1000);
这样配置后请求还是发送到localhost:8080 报404

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhuanglong picture zhuanglong  ·  3Comments

lvzheng0404 picture lvzheng0404  ·  3Comments

2uncle-code picture 2uncle-code  ·  3Comments

yaoleiroyal picture yaoleiroyal  ·  3Comments

Yoping picture Yoping  ·  3Comments