Skip to content

Commit

Permalink
refactor: remove options proxyHost and proxyTable (BREAKING CHANG…
Browse files Browse the repository at this point in the history
…E) (#332)
  • Loading branch information
chimurai authored Apr 4, 2019
1 parent a30a74b commit b13302c
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 107 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
30 changes: 0 additions & 30 deletions dist/config-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
40 changes: 0 additions & 40 deletions src/config-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
34 changes: 0 additions & 34 deletions test/e2e/http-proxy-middleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b13302c

Please sign in to comment.