Skip to content

Commit f5367cf

Browse files
committed
doc: update document.
1 parent 400d176 commit f5367cf

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

packages/core/README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ const proxy = {
9191
proxy: {
9292
// Turn a path string such as `/user/:name` into a regular expression.
9393
// https://www.npmjs.com/package/path-to-regexp
94-
'/repos/(.*)': 'https://api.github.com/',
95-
'/:owner/:repo/raw/:ref/(.*)': 'http://127.0.0.1:2018',
96-
'/api/repos/(.*)': 'http://127.0.0.1:3721/'
94+
'/repos/*path': 'https://api.github.com/',
95+
'/:owner/:repo/raw/:ref/*path': 'http://127.0.0.1:2018',
96+
'/api/repos/*path': 'http://127.0.0.1:3721/'
9797
},
9898
// rewrite target's url path. Object-keys will be used as RegExp to match paths.
9999
// https://github.com/jaywcjlove/mocker-api/issues/62
@@ -137,17 +137,17 @@ const proxy = {
137137
sex: 6
138138
}
139139
],
140-
'GET /api/:owner/:repo/raw/:ref/(.*)': (req, res) => {
140+
'GET /api/:owner/:repo/raw/:ref/*path': (req, res) => {
141141
const { owner, repo, ref } = req.params;
142142
// http://localhost:8081/api/admin/webpack-mock-api/raw/master/add/ddd.md
143143
// owner => admin
144144
// repo => webpack-mock-api
145145
// ref => master
146-
// req.params[0] => add/ddd.md
146+
// req.params.path => add/ddd.md
147147
return res.json({
148148
id: 1,
149149
owner, repo, ref,
150-
path: req.params[0]
150+
path: req.params.path
151151
});
152152
},
153153
'POST /api/login/account': (req, res) => {
@@ -204,6 +204,8 @@ module.exports = proxy;
204204

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

207+
⚠️ No wildcard asterisk ~~`(.*)`~~ - use parameters instead `*path`, support `v3.0.0+`
208+
207209
## Delayed Response
208210

209211
You can use functional tool to enhance mock. [#17](https://github.com/jaywcjlove/webpack-api-mocker/issues/17)
@@ -336,8 +338,8 @@ module.exports = {
336338
+ before(app){
337339
+ apiMocker(app, path.resolve('./mocker/index.js'), {
338340
+ proxy: {
339-
+ '/repos/(.*)': 'https://api.github.com/',
340-
+ '/:owner/:repo/raw/:ref/(.*)': 'http://127.0.0.1:2018'
341+
+ '/repos/*path': 'https://api.github.com/',
342+
+ '/:owner/:repo/raw/:ref/*path': 'http://127.0.0.1:2018'
341343
+ },
342344
+ changeHost: true,
343345
+ })
@@ -387,7 +389,7 @@ Mock API proxying made simple.
387389
before(app){
388390
+ apiMocker(app, path.resolve('./mocker/index.js'), {
389391
+ proxy: {
390-
+ '/repos/(.*)': 'https://api.github.com/',
392+
+ '/repos/*path': 'https://api.github.com/',
391393
+ },
392394
+ changeHost: true,
393395
+ })
@@ -408,7 +410,7 @@ To use api mocker on your [create-react-app](https://github.com/facebook/create-
408410
module.exports = function(app) {
409411
+ apiMocker(app, path.resolve('./mocker/index.js'), {
410412
+ proxy: {
411-
+ '/repos/(.*)': 'https://api.github.com/',
413+
+ '/repos/*path': 'https://api.github.com/',
412414
+ },
413415
+ changeHost: true,
414416
+ });

0 commit comments

Comments
 (0)