-
Notifications
You must be signed in to change notification settings - Fork 858
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(legacyCreateProxyMiddleware): adapter with legacy behavior
- Loading branch information
Showing
14 changed files
with
498 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# Migration guide | ||
|
||
- [v2 to v3 adapter](#v2-to-v3-adapter) | ||
- [`legacyCreateProxyMiddleware`](#legacycreateproxymiddleware) | ||
- [v3 breaking changes](#v3-breaking-changes) | ||
- [Removed `req.url` patching](#removed-requrl-patching) | ||
- [Removed "shorthand" usage](#removed-shorthand-usage) | ||
- [Removed `context` argument](#removed-context-argument) | ||
- [Removed `logProvider` and `logLevel` options](#removed-logprovider-and-loglevel-options) | ||
- [Refactored proxy events](#refactored-proxy-events) | ||
|
||
## v2 to v3 adapter | ||
|
||
### `legacyCreateProxyMiddleware` | ||
|
||
Use the adapter to use v3 without changing too much of your v2 code and configuration. | ||
|
||
NOTE: `legacyCreateProxyMiddleware` will be removed in a future version. | ||
|
||
```js | ||
// before | ||
const { createProxyMiddleware } = require('http-proxy-middleware'); | ||
|
||
createProxyMiddleware(...); | ||
|
||
// after | ||
const { legacyCreateProxyMiddleware } = require('http-proxy-middleware'); | ||
|
||
legacyCreateProxyMiddleware(...); | ||
``` | ||
|
||
```ts | ||
// before | ||
import { createProxyMiddleware, Options } from 'http-proxy-middleware'; | ||
|
||
createProxyMiddleware(...); | ||
|
||
// after | ||
import { legacyCreateProxyMiddleware, LegacyOptions } from 'http-proxy-middleware'; | ||
|
||
legacyCreateProxyMiddleware(...); | ||
``` | ||
|
||
## v3 breaking changes | ||
|
||
### Removed `req.url` patching | ||
|
||
```js | ||
// before | ||
app.use('/user', proxy({ target: 'http://www.example.org' })); | ||
|
||
// after | ||
app.use('/user', proxy({ target: 'http://www.example.org/user' })); | ||
``` | ||
|
||
### Removed "shorthand" usage | ||
|
||
```js | ||
// before | ||
createProxyMiddleware('http:/www.example.org'); | ||
|
||
// after | ||
createProxyMiddleware({ target: 'http:/www.example.org' }); | ||
``` | ||
|
||
### Removed `context` argument | ||
|
||
See [recipes/pathFilter.md](./recipes/pathFilter.md) for more information. | ||
|
||
```js | ||
// before | ||
createProxyMiddleware('/path', { target: 'http://www.example.org' }); | ||
|
||
// after | ||
createProxyMiddleware({ | ||
target: 'http://www.example.org', | ||
pathFilter: '/path', | ||
}); | ||
``` | ||
|
||
### Removed `logProvider` and `logLevel` options | ||
|
||
Use your external logging library to 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 | ||
// new | ||
createProxyMiddleware({ | ||
target: 'http://www.example.org', | ||
logger: console, | ||
}); | ||
```` | ||
### Refactored proxy events | ||
See [recipes/proxy-events.md](./recipes/proxy-events.md) for more information. | ||
```js | ||
// before | ||
createProxyMiddleware({ | ||
target: 'http://www.example.org', | ||
onError: () => {}, | ||
onProxyReq: () => {}, | ||
onProxyRes: () => {}, | ||
onProxyReqWs: () => {}, | ||
onOpen: () => {}, | ||
onClose: () => {}, | ||
}); | ||
|
||
// after | ||
createProxyMiddleware({ | ||
target: 'http://www.example.org', | ||
on: { | ||
error: () => {}, | ||
proxyReq: () => {}, | ||
proxyRes: () => {}, | ||
proxyReqWs: () => {}, | ||
open: () => {}, | ||
close: () => {}, | ||
}, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { createProxyMiddleware } from '..'; | ||
import { Debug } from '../debug'; | ||
import { Filter, RequestHandler } from '../types'; | ||
import { legacyOptionsAdapter } from './options-adapter'; | ||
import { LegacyOptions } from './types'; | ||
|
||
const debug = Debug.extend('legacy-create-proxy-middleware'); | ||
|
||
/** | ||
* @deprecated | ||
* This function is deprecated and will be removed in a future version. | ||
* | ||
* Use {@link createProxyMiddleware} instead. | ||
*/ | ||
export function legacyCreateProxyMiddleware(shortHand: string): RequestHandler; | ||
export function legacyCreateProxyMiddleware(legacyOptions: LegacyOptions): RequestHandler; | ||
export function legacyCreateProxyMiddleware( | ||
legacyContext: Filter, | ||
legacyOptions: LegacyOptions | ||
): RequestHandler; | ||
export function legacyCreateProxyMiddleware(legacyContext, legacyOptions?): RequestHandler { | ||
debug('init'); | ||
|
||
const options = legacyOptionsAdapter(legacyContext, legacyOptions); | ||
|
||
const proxyMiddleware = createProxyMiddleware(options); | ||
|
||
// https://github.com/chimurai/http-proxy-middleware/pull/731/files#diff-07e6ad10bda0df091b737caed42767657cd0bd74a01246a1a0b7ab59c0f6e977L118 | ||
debug('add marker for patching req.url (old behavior)'); | ||
(proxyMiddleware as any).__LEGACY_HTTP_PROXY_MIDDLEWARE__ = true; | ||
|
||
return proxyMiddleware; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './public'; |
Oops, something went wrong.