Skip to content

Commit

Permalink
doc: update document.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Dec 7, 2024
1 parent 400d176 commit f5367cf
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ const proxy = {
proxy: {
// Turn a path string such as `/user/:name` into a regular expression.
// https://www.npmjs.com/package/path-to-regexp
'/repos/(.*)': 'https://api.github.com/',
'/:owner/:repo/raw/:ref/(.*)': 'http://127.0.0.1:2018',
'/api/repos/(.*)': 'http://127.0.0.1:3721/'
'/repos/*path': 'https://api.github.com/',
'/:owner/:repo/raw/:ref/*path': 'http://127.0.0.1:2018',
'/api/repos/*path': 'http://127.0.0.1:3721/'
},
// rewrite target's url path. Object-keys will be used as RegExp to match paths.
// https://github.com/jaywcjlove/mocker-api/issues/62
Expand Down Expand Up @@ -137,17 +137,17 @@ const proxy = {
sex: 6
}
],
'GET /api/:owner/:repo/raw/:ref/(.*)': (req, res) => {
'GET /api/:owner/:repo/raw/:ref/*path': (req, res) => {
const { owner, repo, ref } = req.params;
// http://localhost:8081/api/admin/webpack-mock-api/raw/master/add/ddd.md
// owner => admin
// repo => webpack-mock-api
// ref => master
// req.params[0] => add/ddd.md
// req.params.path => add/ddd.md
return res.json({
id: 1,
owner, repo, ref,
path: req.params[0]
path: req.params.path
});
},
'POST /api/login/account': (req, res) => {
Expand Down Expand Up @@ -204,6 +204,8 @@ module.exports = proxy;

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

⚠️ No wildcard asterisk ~~`(.*)`~~ - use parameters instead `*path`, support `v3.0.0+`

## Delayed Response

You can use functional tool to enhance mock. [#17](https://github.com/jaywcjlove/webpack-api-mocker/issues/17)
Expand Down Expand Up @@ -336,8 +338,8 @@ module.exports = {
+ before(app){
+ apiMocker(app, path.resolve('./mocker/index.js'), {
+ proxy: {
+ '/repos/(.*)': 'https://api.github.com/',
+ '/:owner/:repo/raw/:ref/(.*)': 'http://127.0.0.1:2018'
+ '/repos/*path': 'https://api.github.com/',
+ '/:owner/:repo/raw/:ref/*path': 'http://127.0.0.1:2018'
+ },
+ changeHost: true,
+ })
Expand Down Expand Up @@ -387,7 +389,7 @@ Mock API proxying made simple.
before(app){
+ apiMocker(app, path.resolve('./mocker/index.js'), {
+ proxy: {
+ '/repos/(.*)': 'https://api.github.com/',
+ '/repos/*path': 'https://api.github.com/',
+ },
+ changeHost: true,
+ })
Expand All @@ -408,7 +410,7 @@ To use api mocker on your [create-react-app](https://github.com/facebook/create-
module.exports = function(app) {
+ apiMocker(app, path.resolve('./mocker/index.js'), {
+ proxy: {
+ '/repos/(.*)': 'https://api.github.com/',
+ '/repos/*path': 'https://api.github.com/',
+ },
+ changeHost: true,
+ });
Expand Down

0 comments on commit f5367cf

Please sign in to comment.