(Translated by https://www.hiragana.jp/)
基本使用请求代理如何重写path? · Issue #62 · jaywcjlove/mocker-api · GitHub
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

基本きほん使用しよう请求代理だいり如何いかじゅううつしpath? #62

Closed
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

まんふんかん谢 😄

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

2 participants