Skip to content

Commit

Permalink
docs: minor doc improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai committed Apr 18, 2022
1 parent e144fd9 commit ea4187b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
44 changes: 39 additions & 5 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [`legacyCreateProxyMiddleware`](#legacycreateproxymiddleware)
- [v3 breaking changes](#v3-breaking-changes)
- [Removed `req.url` patching](#removed-requrl-patching)
- [`pathRewrite` (potential behavior change)](#pathrewrite-potential-behavior-change)
- [Removed "shorthand" usage](#removed-shorthand-usage)
- [Removed `context` argument](#removed-context-argument)
- [Removed `logProvider` and `logLevel` options](#removed-logprovider-and-loglevel-options)
Expand All @@ -13,7 +14,7 @@

### `legacyCreateProxyMiddleware`

Use the adapter to use v3 without changing too much of your v2 code and configuration.
Use the adapter to use v3 with minimal changes to your v2 implementation.

NOTE: `legacyCreateProxyMiddleware` will be removed in a future version.

Expand Down Expand Up @@ -53,8 +54,39 @@ app.use('/user', proxy({ target: 'http://www.example.org' }));
app.use('/user', proxy({ target: 'http://www.example.org/user' }));
```

### `pathRewrite` (potential behavior change)

Related to removal of [`req.url` patching](#removed-requrl-patching).

`pathRewrite` now only rewrites the `path` after the mount point.

It was common to rewrite the `basePath` with the `pathRewrite` option:

```js
// before
app.use('/user', proxy({
target: 'http://www.example.org'
pathRewrite: { '^/user': '/secret' }
}));

// after
app.use('/user', proxy({ target: 'http://www.example.org/secret' }));
```

When proxy is mounted at the root, `pathRewrite` should still work as in v2.

```js
// not affected
app.use(proxy({
target: 'http://www.example.org'
pathRewrite: { '^/user': '/secret' }
}));
```

### Removed "shorthand" usage

Specify the `target` option.

```js
// before
createProxyMiddleware('http:/www.example.org');
Expand All @@ -65,6 +97,10 @@ createProxyMiddleware({ target: 'http:/www.example.org' });

### Removed `context` argument

The `context` argument has been moved to option: `pathFilter`.

Functionality did not change.

See [recipes/pathFilter.md](./recipes/pathFilter.md) for more information.

```js
Expand All @@ -80,14 +116,12 @@ createProxyMiddleware({

### Removed `logProvider` and `logLevel` options

Use your external logging library to control the logging level.
Use your external logging library to _log_ and control the logging _level_.

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

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

````js

See [recipes/logger.md](./recipes/logger.md) for more information.

```js
Expand All @@ -96,7 +130,7 @@ createProxyMiddleware({
target: 'http://www.example.org',
logger: console,
});
````
```

### Refactored proxy events

Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ const app = express();

app.use(
'/api',
createProxyMiddleware({ target: 'http://www.example.org/secret', changeOrigin: true })
createProxyMiddleware({
target: 'http://www.example.org/secret',
changeOrigin: true,
})
);

app.listen(3000);

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

app.use(
'/api',
createProxyMiddleware({ target: 'http://www.example.org/api', changeOrigin: true })
createProxyMiddleware({
target: 'http://www.example.org/api',
changeOrigin: true,
})
);

app.listen(3000);

// proxy and keep the same base path "/api"
Expand Down

0 comments on commit ea4187b

Please sign in to comment.