Skip to content

Conversation

@cimc-raffles
Copy link

What kind of change does this PR introduce? (check at least one)

  • [x ] Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • [x ] No

If yes, please describe the impact and migration path for existing applications:

Related issue (if exists):

Other information:
When using the Mock feature, requests with the same URL but different methods cannot be correctly matched because the matching is currently only done based on the request URL. For example, cgiMock({url: '/api/users', method: 'GET'}) and cgiMock({url: '/api/users', method: 'POST'}) will both attempt to match the same mock configuration, which can lead to unexpected behavior.

This change introduces method-based matching to resolve the issue, allowing for distinct mock configurations for different request methods on the same URL.

}
// 请求以 cgiMock.prefix 开头,匹配处理
const matchRequet = requestList.find((item) => req.path.search(item.url) !== -1);
const matchRequet = requestList.find((item) => req.path.search(item.url) !== -1 && req.method === (item.method || 'GET').toUpperCase());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果匹配需要带上请求method的话。正确逻辑应该是:判断item是否有method,如果有再匹配。

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

Successfully merging this pull request may close these issues.

2 participants