http-proxy-middleware
Advanced tools
Comparing version 0.10.0 to 0.11.0
# 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('≈>'); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
122179
2002