Skip to content
New issue

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

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

Already on GitHub? # to your account

基本使用请求代理如何重写path? #62

Closed
zhang0ZGC opened this issue Dec 18, 2019 · 2 comments
Closed

基本使用请求代理如何重写path? #62

zhang0ZGC opened this issue Dec 18, 2019 · 2 comments

Comments

@zhang0ZGC
Copy link

我想在访问 http://localhost/api/client/xxx 的时候,代理到 http://10.1.44.95:8080/sz/api/,所以我写了如下配置:

/* eslint-disable */
const delay = require('mocker-api/utils/delay');

const proxy = {
  _proxy: {
    proxy: {
      '/api/client/(.*)': 'http://10.1.44.95:8080/sz/api/'
    },
    changeHost: true,
  },
};

module.exports=delay(proxy, 0);

但是在请求的时候还是会把/api/client带过去

$ curl http://localhost:3721/api/client/12
{"timestamp":1576654898376,"status":404,"error":"Not Found","message":"Not Found","path":"/sz/api/api/client/12"}

我想要的效果是访问 http://localhost:3721/api/client/12, 就代理到 /sz/api/12

看到 webpack 里面可以用 pathRewrite,单独使用没有找到设置方法

试了好多配置,貌似没有效果啊。。

jaywcjlove added a commit that referenced this issue Dec 18, 2019
jaywcjlove added a commit that referenced this issue Dec 18, 2019
@jaywcjlove
Copy link
Owner

@zhang0ZGC + mocker-api@1.10.0 现在支持类似 webpack 类似的参数设置 pathRewrite

{
  proxy: {
    '/api/repos/(.*)': 'http://127.0.0.1:3721/'
  },
  pathRewrite: {
    '^/api/repos/': '/repos/',
  },
}

@zhang0ZGC
Copy link
Author

万分感谢 😄

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

No branches or pull requests

2 participants