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

Proxy didn't work when proxy and API endpoint configs both exist #97

Open
freezer-glp opened this issue May 4, 2020 · 4 comments
Open

Comments

@freezer-glp
Copy link

Environment

"mocker-api": "^1.12.2"

Issue

I have an back-end API server running locally on port 2080, and I want my front-end which running locally as well to call this local API server, because I want to do integrate test between front-end and back-end.
But I found that Proxy didn't work when proxy and API endpoint configs both exist(just returned the response.json, and API server didn't receive any request ):

(Chinese translation) 我在本地有前端和后端两个服务,后端API server运行于端口2080,如下, 如果我同时配置proxy和endpoint,只会返回/response.json,并没有proxy到2080的API server。这无法完成本地前后端联调测试的需求。

const proxy = {
  _proxy: {
    proxy: {
      '/api/v1/(.*)': 'http://localhost:2080/'
    }
  },

  // API endpoint describe here
   'GET /api/v1/login/:userId': (req, res) => {
     return res.json(require('./response.json'));
   }
 
};
module.exports = proxy;

If I remove the endpoint config, front end will call proxy which is http://localhost:2080/:

(Chinese translation) 如果我删除endpoint配置,只留proxy,这时/api/v1/login/可以转发到我的本地2080 API server中。

const proxy = {
  _proxy: {
    proxy: {
      '/api/v1/(.*)': 'http://localhost:2080/'
    }
  },

  // API endpoint describe here  (REMOVE IT !)
  // 'GET /api/v1/login/:userId': (req, res) => {
  //    return res.json(require('./response.json'));
  // }
 
};
module.exports = proxy;

Then the API server locally will receive request call for /api/v1/login/:userId now.


Please help about what's wrong here?
Thanks

@jaywcjlove
Copy link
Owner

@freezer-glp 可以参考实例中配置 _proxy 只是个方便的配置,另外个地方可以配置,是不是冲突了

@freezer-glp
Copy link
Author

@jaywcjlove
Thx for your reply.

我参考了示例配置,依旧不行。能否给我个example链接?

你是否测试过我这种配置方法?当两者(proxy和endpoint)都配置的情况下,是否proxy不起作用,而endpoint的优先级更高?

@jaywcjlove
Copy link
Owner

@freezer-glp
Copy link
Author

@freezer-glp https://github.com/jaywcjlove/mocker-api/tree/master/example

没有看到使用
proxy: { '/api/v1/(.*)': 'http://localhost:2080/' }
的例子,都被注释了。

你是否测试过我这种配置方法?当两者(proxy和endpoint)都配置的情况下,是否proxy不起作用,而endpoint的优先级更高?

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