Skip to content

Commit ced7b9d

Browse files
authored
docs(pathRewrite): fix examples (chimurai#118)
1 parent f03aecf commit ced7b9d

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ var options = {
107107
changeOrigin: true, // needed for virtual hosted sites
108108
ws: true, // proxy websockets
109109
pathRewrite: {
110-
'^/old/api' : '/new/api', // rewrite path
111-
'^/remove/api' : '/api' // remove path
110+
'^/api/old-path' : '/api/new-path', // rewrite path
111+
'^/api/remove/path' : '/path' // remove base path
112112
},
113113
router: {
114114
// when request.headers.host == 'dev.localhost:3000',

recipes/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ var options = {
3838

3939
// rewrite paths
4040
pathRewrite: {
41-
'^/old/api': '/new/api', // rewrite path
42-
'^/remove/api': '' // remove path
41+
'^/api/old-path' : '/api/new-path', // rewrite path
42+
'^/api/remove/path' : '/path' // remove base path
4343
},
4444

4545
// re-target based on the request's host header and/or path

recipes/pathRewrite.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Modify request paths before requests are send to the target.
1717
Rewrite paths
1818

1919
```javascript
20-
var proxy = require("http-proxy-middleware");
20+
var proxy = require('http-proxy-middleware');
2121

2222
var options = {
2323
target: 'http://localhost:3000',
2424
pathRewrite: {
25-
"^/old/api" : "/new/api" // rewrite path
26-
}
25+
'^/api/old-path' : '/api/new-path', // rewrite path
26+
},
2727
};
2828

2929
var apiProxy = proxy('/api', options);
@@ -36,31 +36,31 @@ var apiProxy = proxy('/api', options);
3636
Remove base path
3737

3838
```javascript
39-
var proxy = require("http-proxy-middleware");
39+
var proxy = require('http-proxy-middleware');
4040

4141
var options = {
4242
target: 'http://localhost:3000',
4343
pathRewrite: {
44-
"^/remove/api" : "" // remove base path
44+
'^/api/' : '/' // remove base path
4545
}
4646
};
4747

4848
var apiProxy = proxy('/api', options);
4949

50-
// `/remove/api/lorum/ipsum` -> `http://localhost:3000/lorum/ipsum`
50+
// `/api/lorum/ipsum` -> `http://localhost:3000/lorum/ipsum`
5151
```
5252

5353
## add paths
5454

5555
Add base path
5656

5757
```javascript
58-
var proxy = require("http-proxy-middleware");
58+
var proxy = require('http-proxy-middleware');
5959

6060
var options = {
6161
target: 'http://localhost:3000',
6262
pathRewrite: {
63-
"^/" : "/extra/" // add base path
63+
'^/' : '/extra/' // add base path
6464
}
6565
};
6666

@@ -76,7 +76,7 @@ Implement you own path rewrite logic.
7676
The unmodified path will be used, when rewrite function returns `undefined`
7777

7878
```javascript
79-
var proxy = require("http-proxy-middleware");
79+
var proxy = require('http-proxy-middleware');
8080

8181
var rewriteFn = function (path, req) {
8282
return path.replace('/api/foo', '/api/bar');

0 commit comments

Comments
 (0)