Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 43e2bb6

Browse filesBrowse files
committed
feat(legacyCreateProxyMiddleware): show migration tips
1 parent cdfe934 commit 43e2bb6
Copy full SHA for 43e2bb6

File tree

Expand file treeCollapse file tree

2 files changed

+49
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+49
-1
lines changed

‎src/legacy/options-adapter.ts

Copy file name to clipboardExpand all lines: src/legacy/options-adapter.ts
+48-1Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import * as url from 'url';
22
import { Filter, Options } from '..';
33
import { LegacyOptions } from './types';
44
import { Debug } from '../debug';
5+
import { getLogger } from '../logger';
6+
import { Logger } from '../types';
57

68
const debug = Debug.extend('legacy-options-adapter');
79

@@ -23,6 +25,7 @@ export function legacyOptionsAdapter(
2325
legacyOptions: LegacyOptions
2426
): Options {
2527
let options: LegacyOptions;
28+
let logger: Logger;
2629

2730
// https://github.com/chimurai/http-proxy-middleware/pull/716
2831
if (typeof legacyContext === 'string' && !!url.parse(legacyContext).host) {
@@ -37,8 +40,21 @@ export function legacyOptionsAdapter(
3740
if (legacyContext && legacyOptions) {
3841
debug('map legacy context/filter to options.pathFilter');
3942
options = { ...legacyOptions, pathFilter: legacyContext as Filter };
43+
logger = getLegacyLogger(options);
44+
45+
logger.warn(
46+
`[http-proxy-middleware] Legacy "context" argument is deprecated. Migrate your "context" to "options.pathFilter":
47+
48+
const options = {
49+
pathFilter: '${legacyContext}',
50+
}
51+
52+
More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md
53+
`
54+
);
4055
} else if (legacyContext && !legacyOptions) {
4156
options = { ...(legacyContext as Options) };
57+
logger = getLegacyLogger(options);
4258
}
4359

4460
// map old event names to new event names
@@ -48,6 +64,19 @@ export function legacyOptionsAdapter(
4864
options.on = { ...options.on };
4965
options.on[proxyEventName] = options[legacyEventName];
5066
debug('map legacy event "%s" to "on.%s"', legacyEventName, proxyEventName);
67+
68+
logger.warn(
69+
`[http-proxy-middleware] Legacy "${legacyEventName}" is deprecated. Migrate to "options.on.${proxyEventName}":
70+
71+
const options = {
72+
on: {
73+
${proxyEventName}: () => {},
74+
},
75+
}
76+
77+
More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md
78+
`
79+
);
5180
}
5281
});
5382

@@ -59,9 +88,27 @@ export function legacyOptionsAdapter(
5988
debug('legacy logProvider: %O', logProvider);
6089

6190
if (typeof logLevel === 'string' && logLevel !== 'silent') {
62-
options.logger = logProvider;
6391
debug('map "logProvider" to "logger"');
92+
93+
logger.warn(
94+
`[http-proxy-middleware] Legacy "logLevel" and "logProvider" are deprecated. Migrate to "options.logger":
95+
96+
const options = {
97+
logger: console,
98+
}
99+
100+
More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md
101+
`
102+
);
64103
}
65104

66105
return options;
67106
}
107+
108+
function getLegacyLogger(options): Logger {
109+
const legacyLogger = options.logProvider && options.logProvider();
110+
if (legacyLogger) {
111+
options.logger = legacyLogger;
112+
}
113+
return getLogger(options);
114+
}

‎test/legacy/http-proxy-middleware.spec.ts

Copy file name to clipboardExpand all lines: test/legacy/http-proxy-middleware.spec.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,6 @@ describe('legacyCreateProxyMiddleware()', () => {
100100
expect(response.text).toBe('my legacy error');
101101

102102
expect(mockLogger.error).toHaveBeenCalledTimes(1);
103+
expect(mockLogger.warn).toHaveBeenCalledTimes(2);
103104
});
104105
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.