Skip to content

Commit

Permalink
fix: improve path matching logic, fix #25
Browse files Browse the repository at this point in the history
  • Loading branch information
vben-admin committed May 31, 2021
1 parent fdfed60 commit 5079e4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion es/createProdMockServer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable */
import mockJs from 'mockjs';
import { pathToRegexp } from 'path-to-regexp';
const Mock = mockJs;
export function createProdMockServer(mockList) {
Mock.XHR.prototype.__send = Mock.XHR.prototype.send;
Expand Down Expand Up @@ -31,7 +32,11 @@ export function createProdMockServer(mockList) {
};
for (const { url, method, response, timeout } of mockList) {
__setupMock__(timeout);
Mock.mock(new RegExp(url), method || 'get', __XHR2ExpressReqWrapper__(response));
Mock.mock(
pathToRegexp(url, undefined, { end: false }),
method || 'get',
__XHR2ExpressReqWrapper__(response)
);
}
}
function __param2Obj__(url) {
Expand Down
7 changes: 6 additions & 1 deletion src/createProdMockServer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable */
import mockJs from 'mockjs';
import { pathToRegexp } from 'path-to-regexp';

const Mock = mockJs as any;
export function createProdMockServer(mockList: any[]) {
Expand Down Expand Up @@ -36,7 +37,11 @@ export function createProdMockServer(mockList: any[]) {

for (const { url, method, response, timeout } of mockList) {
__setupMock__(timeout);
Mock.mock(new RegExp(url), method || 'get', __XHR2ExpressReqWrapper__(response));
Mock.mock(
pathToRegexp(url, undefined, { end: false }),
method || 'get',
__XHR2ExpressReqWrapper__(response)
);
}
}

Expand Down

0 comments on commit 5079e4b

Please sign in to comment.