Socket
Socket
Sign inDemoInstall

http-proxy-middleware

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-proxy-middleware - npm Package Compare versions

Comparing version 0.10.0 to 0.11.0

7

CHANGELOG.md
# Changelog
## [v0.11.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.11.0)
- improved logging
## [v0.10.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.10.0)
- feat(proxyTable) - added proxyTable support for WebSockets.
- fixed(proxyTable) - ensure original path (not rewritten path) is being used when `proxyTable` is used in conjunction with `pathRewrite`.
## [v0.9.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.9.1)

@@ -4,0 +11,0 @@ - fix server crash when socket error not handled correctly.

29

index.js

@@ -9,2 +9,3 @@ var _ = require('lodash');

var logger = require('./lib/logger').getInstance();
var getArrow = require('./lib/logger').getArrow;

@@ -60,9 +61,4 @@ var httpProxyMiddleware = function (context, opts) {

if (contextMatcher.match(config.context, req.url)) {
logger.debug('[HPM] Context match: "%s" -> "%s"', config.context, req.url);
var activeProxyOptions = __prepareProxyRequest(req);
logger.debug('[HPM] Proxying "%s": "%s" -> "%s"', req.url, req.hostname, activeProxyOptions.target);
var activeProxyOptions = prepareProxyRequest(req);
proxy.web(req, res, activeProxyOptions);
} else {

@@ -89,5 +85,3 @@ next();

if (contextMatcher.match(config.context, req.url)) {
var activeProxyOptions = __prepareProxyRequest(req);
var activeProxyOptions = prepareProxyRequest(req);
proxy.ws(req, socket, head, activeProxyOptions);

@@ -104,9 +98,16 @@ logger.info('[HPM] Upgrading to WebSocket');

*/
function __prepareProxyRequest(req) {
// apply option.proxyTable
function prepareProxyRequest(req) {
// store uri before it gets rewritten for logging
var originalPath = req.url;
// apply apply option.proxyTable & option.pathRewrite
var alteredProxyOptions = __applyProxyTableOption(req, proxyOptions);
// apply option.pathRewrite
__applyPathRewrite(req, pathRewriter);
// debug logging for both http(s) and websockets
if (proxyOptions.logLevel === 'debug') {
var arrow = getArrow(originalPath, req.url, proxyOptions.target, alteredProxyOptions.target);
logger.debug('[HPM] %s %s %s %s', req.method, originalPath, arrow, alteredProxyOptions.target);
}
return alteredProxyOptions;

@@ -146,3 +147,3 @@ }

logger.error('[HPM] Proxy error: %s. %s -> "%s"', err.code, hostname, targetUri);
logger.error('[HPM] PROXY ERROR: %s. %s -> %s', err.code, hostname, targetUri);
}

@@ -149,0 +150,0 @@

@@ -31,3 +31,4 @@ var util = require('util');

return loggerInstance;
}
},
getArrow : getArrow
};

@@ -145,1 +146,19 @@

/**
* -> normal proxy
* => proxyTable
* ~> pathRewrite
* ≈> proxyTable + pathRewrite
*/
function getArrow (originalPath, newPath, originalTarget, newTarget) {
var arrow = ['>'];
var isNewTarget = (originalTarget !== newTarget); // proxyTable
var isNewPath = (originalPath !== newPath); // pathRewrite
if (isNewPath && !isNewTarget) {arrow.unshift('~');}
else if (!isNewPath && isNewTarget) {arrow.unshift('=');}
else if (isNewPath && isNewTarget) {arrow.unshift('≈');}
else {arrow.unshift('-');}
return arrow.join('');
}

@@ -48,3 +48,3 @@ var _ = require('lodash');

});
logger.info('[HPM] Proxy rewrite rule created: "%s" -> "%s"', key, config[key]);
logger.info('[HPM] Proxy rewrite rule created: "%s" ~> "%s"', key, config[key]);
});

@@ -51,0 +51,0 @@

{
"name": "http-proxy-middleware",
"version": "0.10.0",
"version": "0.11.0",
"description": "The one-liner node.js proxy middleware for connect, express and browser-sync",

@@ -5,0 +5,0 @@ "main": "index.js",

var expect = require('chai').expect;
var Logger = require('../lib/logger');
var getArrow = require('../lib/logger').getArrow;

@@ -212,6 +213,49 @@ describe('Logger', function () {

});
});
describe('getArrow', function () {
var arrow;
// scenario = [originalPath, newPath, originalTarget, newTarget]
describe('default arrow', function () {
beforeEach(function () {
arrow = getArrow('/api', '/api', 'localhost:1337', 'localhost:1337');
});
it('should return arrow: "->"', function () {
expect(arrow).to.equal('->');
});
});
describe('"pathRewrite" arrow', function () {
beforeEach(function () {
arrow = getArrow('/api', '/rest', 'localhost:1337', 'localhost:1337');
});
it('should return arrow: "~>"', function () {
expect(arrow).to.equal('~>');
});
});
describe('"proxyTable" arrow', function () {
beforeEach(function () {
arrow = getArrow('/api', '/api', 'localhost:1337', 'localhost:8888');
});
it('should return arrow: "=>"', function () {
expect(arrow).to.equal('=>');
});
});
describe('"pathRewrite" + "proxyTable" arrow', function () {
beforeEach(function () {
arrow = getArrow('/api', '/rest', 'localhost:1337', 'localhost:8888');
});
it('should return arrow: "≈>"', function () {
expect(arrow).to.equal('≈>');
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc