Skip to content

Commit 9e1f059

Browse files
committed
fix(deps): update dependency express to ~v5.
1 parent 8e8e340 commit 9e1f059

6 files changed

Lines changed: 20 additions & 17 deletions

File tree

README-zh.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ const proxy = {
123123
proxy: {
124124
// 将路径字符串(例如`/user/:name`)转换为正则表达式。
125125
// https://www.npmjs.com/package/path-to-regexp
126-
'/repos/(.*)': 'https://api.github.com/',
127-
'/:owner/:repo/raw/:ref/(.*)': 'http://127.0.0.1:2018',
128-
'/api/repos/(.*)': 'http://127.0.0.1:3721/'
126+
'/repos/*path': 'https://api.github.com/',
127+
'/:owner/:repo/raw/:ref/*path': 'http://127.0.0.1:2018',
128+
'/api/repos/*path': 'http://127.0.0.1:3721/'
129129
},
130130
// 重写目标网址路径。对象键将用作RegEx来匹配路径。
131131
// https://github.com/jaywcjlove/mocker-api/issues/62
@@ -169,17 +169,17 @@ const proxy = {
169169
sex: 6
170170
}
171171
],
172-
'GET /api/:owner/:repo/raw/:ref/(.*)': (req, res) => {
172+
'GET /api/:owner/:repo/raw/:ref/*path': (req, res) => {
173173
const { owner, repo, ref } = req.params;
174174
// http://localhost:8081/api/admin/webpack-mock-api/raw/master/add/ddd.md
175175
// owner => admin
176176
// repo => webpack-mock-api
177177
// ref => master
178-
// req.params[0] => add/ddd.md
178+
// req.params.path => add/ddd.md
179179
return res.json({
180180
id: 1,
181181
owner, repo, ref,
182-
path: req.params[0]
182+
path: req.params.path
183183
});
184184
},
185185
'POST /api/login/account': (req, res) => {
@@ -236,6 +236,10 @@ module.exports = proxy;
236236

237237
⚠️ No wildcard asterisk ~~`*`~~ - use parameters instead `(.*)`, support `v1.7.3+`
238238

239+
⚠️ No wildcard asterisk ~~`(.*)`~~ - use parameters instead `*path`, support `v3.0.0+`
240+
241+
⚠️ 使用 `path-to-regexp@8+` 时,请避免使用 `/*``(.*)`,统一使用命名通配参数,例如 `/*path`
242+
239243
## 延迟响应
240244

241245
您可以使用功能性工具来增强模拟效果。[#17](https://github.com/jaywcjlove/webpack-api-mocker/issues/17)
@@ -363,8 +367,8 @@ module.exports = {
363367
+ before(app){
364368
+ apiMocker(app, path.resolve('./mocker/index.js'), {
365369
+ proxy: {
366-
+ '/repos/*': 'https://api.github.com/',
367-
+ '/:owner/:repo/raw/:ref/*': 'http://127.0.0.1:2018'
370+
+ '/repos/*path': 'https://api.github.com/',
371+
+ '/:owner/:repo/raw/:ref/*path': 'http://127.0.0.1:2018'
368372
+ },
369373
+ changeHost: true,
370374
+ })
@@ -414,7 +418,7 @@ Mock API proxying made simple.
414418
before(app){
415419
+ apiMocker(app, path.resolve('./mocker/index.js'), {
416420
+ proxy: {
417-
+ '/repos/*': 'https://api.github.com/',
421+
+ '/repos/*path': 'https://api.github.com/',
418422
+ },
419423
+ changeHost: true,
420424
+ })
@@ -435,7 +439,7 @@ Mock API proxying made simple.
435439
module.exports = function(app) {
436440
+ apiMocker(app, path.resolve('./mocker/index.js'), {
437441
+ proxy: {
438-
+ '/repos/(.*)': 'https://api.github.com/',
442+
+ '/repos/*path': 'https://api.github.com/',
439443
+ },
440444
+ changeHost: true,
441445
+ });

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
}
3737
},
3838
"devDependencies": {
39+
"express": "~5.2.1",
3940
"lerna": "^8.0.0",
4041
"tsbb": "^4.1.3",
4142
"typedoc": "~0.23.0"

packages/core/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,18 @@
4343
"TypeScript"
4444
],
4545
"dependencies": {
46-
"body-parser": "~1.20.1",
4746
"chokidar": "~5.0.0",
4847
"clear-module": "~4.1.2",
4948
"colors-cli": "~1.0.28",
5049
"detect-port": "~2.1.0",
51-
"express": "~4.21.0",
50+
"express": "~5.2.1",
5251
"http-proxy": "~1.18.1",
5352
"local-ip-url": "~1.0.3",
5453
"minimist": "~1.2.7",
5554
"path-to-regexp": "~8.2.0"
5655
},
5756
"devDependencies": {
58-
"@types/body-parser": "~1.19.2",
59-
"@types/express": "~4.17.14",
57+
"@types/express": "~5.0.6",
6058
"@types/http-proxy": "~1.17.9",
6159
"@types/minimist": "~1.2.2",
6260
"@types/node": "~18.14.0"

packages/core/src/__test__/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('mockerApi watch mode', () => {
8383

8484
expect(watchMock).toHaveBeenCalledWith([path.dirname(require.resolve(mockFile))], { ignoreInitial: true });
8585
expect(onMock).toHaveBeenCalledWith('all', expect.any(Function));
86-
expect(app.all).toHaveBeenCalledWith('/*', expect.any(Function));
86+
expect(app.all).toHaveBeenCalledWith(/.*/, expect.any(Function));
8787
});
8888

8989
it('handles watched file changes through the hot reload path', () => {

packages/core/src/bin/mocker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const DEFAULT_CONFIG: MockerConfig = {
9494
const DEFAULT_HOST = mockerConfig.host;
9595
const app = express();
9696

97-
app.all('/*', (req, res, next) => {
97+
app.all(/.*/, (req, res, next) => {
9898
console.log(`${color.green(req.method)} - ${req.url}`);
9999
res.header('Access-Control-Allow-Origin', '*');
100100
res.header('Access-Control-Allow-Headers', 'Content-Type,Content-Length,Authorization,Accept,X-Requested-With');

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export default function mockerApi(app: Application, watchFile: string | string[]
267267
}
268268
// 监听文件修改重新加载代码
269269
// 配置热更新
270-
app.all('/*', (req: Request, res: Response, next: NextFunction) => {
270+
app.all(/.*/, (req: Request, res: Response, next: NextFunction) => {
271271
const getExecUrlPath = (req: Request) => {
272272
return options.withFullUrlPath ? req.url : req.path;
273273
}

0 commit comments

Comments
 (0)