From b13302c87a04bf7adc4c2547affaaeeb7ecb0c42 Mon Sep 17 00:00:00 2001 From: chimurai <655241+chimurai@users.noreply.github.com> Date: Thu, 4 Apr 2019 23:15:12 +0200 Subject: [PATCH] refactor: remove options `proxyHost` and `proxyTable` (BREAKING CHANGE) (#332) --- CHANGELOG.md | 1 + README.md | 3 -- dist/config-factory.js | 30 ------------------- src/config-factory.ts | 40 -------------------------- test/e2e/http-proxy-middleware.spec.ts | 34 ---------------------- 5 files changed, 1 insertion(+), 107 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4764b2ed..c5774b2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - refactor: migrate to typescript ([#328](https://github.com/chimurai/http-proxy-middleware/pull/328)) - feat(middleware): Promise / async support ([#328](https://github.com/chimurai/http-proxy-middleware/pull/328/files#diff-7890bfeb41abb0fc0ef2670749c84077R50)) +- refactor: remove legacy options `proxyHost` and `proxyTable` (BREAKING CHANGE) ## [v0.19.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.19.1) diff --git a/README.md b/README.md index fd41681a..35507eb9 100644 --- a/README.md +++ b/README.md @@ -247,9 +247,6 @@ Providing an alternative way to decide which requests should be proxied; In case } ``` -- (DEPRECATED) **option.proxyHost**: Use `option.changeOrigin = true` instead. -- (DEPRECATED) **option.proxyTable**: Use `option.router` instead. - ### http-proxy events Subscribe to [http-proxy events](https://github.com/nodejitsu/node-http-proxy#listening-for-proxy-events): diff --git a/dist/config-factory.js b/dist/config-factory.js index 9924eba6..a4c47092 100644 --- a/dist/config-factory.js +++ b/dist/config-factory.js @@ -36,10 +36,6 @@ function createConfig(context, opts) { if (!config.options.target) { throw new Error(errors_1.ERRORS.ERR_CONFIG_FACTORY_TARGET_MISSING); } - // Legacy option.proxyHost - config.options = mapLegacyProxyHostOption(config.options); - // Legacy option.proxyTable > option.router - config.options = mapLegacyProxyTableOption(config.options); return config; } exports.createConfig = createConfig; @@ -73,32 +69,6 @@ function isStringShortHand(context) { function isContextless(context, opts) { return _.isPlainObject(context) && _.isEmpty(opts); } -function mapLegacyProxyHostOption(options) { - // set options.headers.host when option.proxyHost is provided - if (options.proxyHost) { - logger.warn('*************************************'); - logger.warn('[HPM] Deprecated "option.proxyHost"'); - logger.warn(' Use "option.changeOrigin" or "option.headers.host" instead'); - logger.warn(' "option.proxyHost" will be removed in future release.'); - logger.warn('*************************************'); - options.headers = options.headers || {}; - options.headers.host = options.proxyHost; - } - return options; -} -// Warn deprecated proxyTable api usage -function mapLegacyProxyTableOption(options) { - if (options.proxyTable) { - logger.warn('*************************************'); - logger.warn('[HPM] Deprecated "option.proxyTable"'); - logger.warn(' Use "option.router" instead'); - logger.warn(' "option.proxyTable" will be removed in future release.'); - logger.warn('*************************************'); - options.router = _.clone(options.proxyTable); - _.omit(options, 'proxyTable'); - } - return options; -} function configureLogger(options) { if (options.logLevel) { logger.setLevel(options.logLevel); diff --git a/src/config-factory.ts b/src/config-factory.ts index 0fa2528c..7240b50a 100644 --- a/src/config-factory.ts +++ b/src/config-factory.ts @@ -41,12 +41,6 @@ export function createConfig(context, opts?) { throw new Error(ERRORS.ERR_CONFIG_FACTORY_TARGET_MISSING); } - // Legacy option.proxyHost - config.options = mapLegacyProxyHostOption(config.options); - - // Legacy option.proxyTable > option.router - config.options = mapLegacyProxyTableOption(config.options); - return config; } @@ -82,40 +76,6 @@ function isContextless(context, opts) { return _.isPlainObject(context) && _.isEmpty(opts); } -function mapLegacyProxyHostOption(options) { - // set options.headers.host when option.proxyHost is provided - if (options.proxyHost) { - logger.warn('*************************************'); - logger.warn('[HPM] Deprecated "option.proxyHost"'); - logger.warn( - ' Use "option.changeOrigin" or "option.headers.host" instead' - ); - logger.warn(' "option.proxyHost" will be removed in future release.'); - logger.warn('*************************************'); - - options.headers = options.headers || {}; - options.headers.host = options.proxyHost; - } - - return options; -} - -// Warn deprecated proxyTable api usage -function mapLegacyProxyTableOption(options) { - if (options.proxyTable) { - logger.warn('*************************************'); - logger.warn('[HPM] Deprecated "option.proxyTable"'); - logger.warn(' Use "option.router" instead'); - logger.warn(' "option.proxyTable" will be removed in future release.'); - logger.warn('*************************************'); - - options.router = _.clone(options.proxyTable); - _.omit(options, 'proxyTable'); - } - - return options; -} - function configureLogger(options) { if (options.logLevel) { logger.setLevel(options.logLevel); diff --git a/test/e2e/http-proxy-middleware.spec.ts b/test/e2e/http-proxy-middleware.spec.ts index e3562efd..196e0de8 100644 --- a/test/e2e/http-proxy-middleware.spec.ts +++ b/test/e2e/http-proxy-middleware.spec.ts @@ -348,40 +348,6 @@ describe('E2E http-proxy-middleware', () => { }); }); - describe('legacy option.proxyHost', () => { - let proxyServer; - let targetServer; - let targetHeaders; - - beforeEach(done => { - const mwProxy = proxyMiddleware('/api', { - target: 'http://localhost:8000', - proxyHost: 'foobar.dev' - }); - - const mwTarget = (req, res, next) => { - targetHeaders = req.headers; - res.end(); - }; - - proxyServer = createServer(3000, mwProxy); - targetServer = createServer(8000, mwTarget); - - http.get('http://localhost:3000/api/', res => { - done(); - }); - }); - - afterEach(() => { - proxyServer.close(); - targetServer.close(); - }); - - it('should proxy host header to target server', () => { - expect(targetHeaders.host).toBe('foobar.dev'); - }); - }); - describe('option.onError - Error handling', () => { let proxyServer; let targetServer;