Skip to content

Commit 005682c

Browse files
committed
docs: minor doc improvements
1 parent e144fd9 commit 005682c

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

MIGRATION.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- [`legacyCreateProxyMiddleware`](#legacycreateproxymiddleware)
55
- [v3 breaking changes](#v3-breaking-changes)
66
- [Removed `req.url` patching](#removed-requrl-patching)
7+
- [`pathRewrite` (potential behavior change)](#pathrewrite-potential-behavior-change)
78
- [Removed "shorthand" usage](#removed-shorthand-usage)
89
- [Removed `context` argument](#removed-context-argument)
910
- [Removed `logProvider` and `logLevel` options](#removed-logprovider-and-loglevel-options)
@@ -53,8 +54,39 @@ app.use('/user', proxy({ target: 'http://www.example.org' }));
5354
app.use('/user', proxy({ target: 'http://www.example.org/user' }));
5455
```
5556

57+
### `pathRewrite` (potential behavior change)
58+
59+
Related to removal of [`req.url` patching](#removed-requrl-patching).
60+
61+
`pathRewrite` now only rewrites the `path` after the mount point.
62+
63+
It was common to rewrite the `basePath` with the `pathRewrite` option:
64+
65+
```js
66+
// before
67+
app.use('/user', proxy({
68+
target: 'http://www.example.org'
69+
pathRewrite: { '^/user': '/secret' }
70+
}));
71+
72+
// after
73+
app.use('/user', proxy({ target: 'http://www.example.org/secret' }));
74+
```
75+
76+
When proxy is mounted at the root, `pathRewrite` should still work as in v2.
77+
78+
```js
79+
// not affected
80+
app.use(proxy({
81+
target: 'http://www.example.org'
82+
pathRewrite: { '^/user': '/secret' }
83+
}));
84+
```
85+
5686
### Removed "shorthand" usage
5787

88+
Specify the `target` option.
89+
5890
```js
5991
// before
6092
createProxyMiddleware('http:/www.example.org');
@@ -65,6 +97,10 @@ createProxyMiddleware({ target: 'http:/www.example.org' });
6597

6698
### Removed `context` argument
6799

100+
The `context` argument has been moved to option: `pathFilter`.
101+
102+
Functionality did not change.
103+
68104
See [recipes/pathFilter.md](./recipes/pathFilter.md) for more information.
69105

70106
```js
@@ -80,14 +116,12 @@ createProxyMiddleware({
80116

81117
### Removed `logProvider` and `logLevel` options
82118

83-
Use your external logging library to control the logging level.
119+
Use your external logging library to _log_ and control the logging _level_.
84120

85121
Only `info`, `warn`, `error` are used internally for compatibility across different loggers.
86122

87123
If you use `winston`, make sure to enable interpolation: <https://github.com/winstonjs/winston#string-interpolation>
88124

89-
````js
90-
91125
See [recipes/logger.md](./recipes/logger.md) for more information.
92126

93127
```js
@@ -96,7 +130,7 @@ createProxyMiddleware({
96130
target: 'http://www.example.org',
97131
logger: console,
98132
});
99-
````
133+
```
100134

101135
### Refactored proxy events
102136

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ const app = express();
3636

3737
app.use(
3838
'/api',
39-
createProxyMiddleware({ target: 'http://www.example.org/secret', changeOrigin: true })
39+
createProxyMiddleware({
40+
target: 'http://www.example.org/secret',
41+
changeOrigin: true,
42+
})
4043
);
44+
4145
app.listen(3000);
4246

4347
// proxy and change the base path from "/api" to "/secret"
@@ -54,8 +58,12 @@ const app = express();
5458

5559
app.use(
5660
'/api',
57-
createProxyMiddleware({ target: 'http://www.example.org/api', changeOrigin: true })
61+
createProxyMiddleware({
62+
target: 'http://www.example.org/api',
63+
changeOrigin: true,
64+
})
5865
);
66+
5967
app.listen(3000);
6068

6169
// proxy and keep the same base path "/api"

0 commit comments

Comments
 (0)