Repository: chimurai/http-proxy-middleware
Pull request #332 (2019-04-04 20:55:39)

refactor: remove options `proxyHost` and `proxyTable` (BREAKING CHANGE)

coveralls: 
[![Coverage Status](https://coveralls.io/builds/22612283/badge)](https://coveralls.io/builds/22612283)

Coverage increased (+3.2%) to 92.842% when pulling **7fffa74cf5810aa9ae62be8ac43bfdd9c4ecb3e9 on legacy-removal** into **a30a74b91dc4bd042ecf292d7862ec17e187baf1 on master**.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4764b2e..c5774b2 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 fd41681..35507eb 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 9924eba..a4c4709 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 0fa2528..7240b50 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);


Test patch:
diff --git a/test/e2e/http-proxy-middleware.spec.ts b/test/e2e/http-proxy-middleware.spec.ts
index e3562ef..196e0de 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;