dynamic-reverse-proxy
Advanced tools
Comparing version 0.4.5 to 0.5.0
@@ -6,4 +6,4 @@ var httpProxy = require("http-proxy"), | ||
this.routes = {}; | ||
this.proxy = new httpProxy.RoutingProxy(); | ||
this.proxy.on("proxyError", _onProxyError.bind(this)); | ||
this.proxy = httpProxy.createProxyServer(); | ||
this.proxy.on("error", _onProxyError.bind(this)); | ||
}; | ||
@@ -34,2 +34,10 @@ | ||
DynamicProxy.prototype.registerRoute = function (route) { | ||
route.prefix = route.prefix.replace(/\/+$/, '') || route.prefix; | ||
route.prefix = (route.prefix[0] === "/" ? route.prefix : "/" + route.prefix).toLowerCase(); | ||
route.host = "localhost"; | ||
this.routes[route.prefix] = route; | ||
this.emit("routeRegistered", route); | ||
}; | ||
var _onProxyError = function (error, req, res) { | ||
@@ -63,6 +71,6 @@ this.emit("proxyError", error, req.host, req, res); | ||
var host; | ||
var route; | ||
try { | ||
host = JSON.parse(req.body); | ||
route = JSON.parse(req.body); | ||
} | ||
@@ -78,3 +86,3 @@ catch (e) { | ||
if (!(host && host.prefix && host.port)) { | ||
if (!(route && route.prefix && route.port)) { | ||
this.emit("registerError", new Error("INCOMPLETE_REQUEST"), req, res); | ||
@@ -88,19 +96,14 @@ | ||
this.registerRoute(route); | ||
host.prefix = host.prefix.replace(/\/+$/, '') || host.prefix; | ||
host.prefix = (host.prefix[0] === "/" ? host.prefix : "/" + host.prefix).toLowerCase(); | ||
host.host = "localhost"; | ||
res.statusCode = 200; | ||
this.routes[host.prefix] = host; | ||
res.statusCode = 200; | ||
res.write(JSON.stringify({ | ||
message: "Registered.", | ||
host: host.host, | ||
port: host.port, | ||
prefix: host.prefix | ||
host: route.host, | ||
port: route.port, | ||
prefix: route.prefix | ||
})); | ||
res.end(); | ||
this.emit("routeRegistered", host); | ||
}; | ||
@@ -134,4 +137,5 @@ | ||
req.host = Object.create(host); | ||
res.setHeader("x-served-by", "http://" + host.host + ":" + host.port + host.prefix); | ||
this.proxy.proxyRequest(req, res, host); | ||
var target = "http://" + host.host + ":" + host.port; | ||
res.setHeader("x-served-by", target + host.prefix); | ||
this.proxy.web(req, res, { target: target }); | ||
}; |
{ | ||
"author": "Andrew Dunkman <andrew@dunkman.org>", | ||
"name": "dynamic-reverse-proxy", | ||
"version": "0.4.5", | ||
"version": "0.5.0", | ||
"repository": { | ||
@@ -9,3 +9,3 @@ "url": "git://github.com/softek/dynamic-reverse-proxy.git" | ||
"dependencies": { | ||
"http-proxy": "0.8.5" | ||
"http-proxy": "1.1.4" | ||
}, | ||
@@ -12,0 +12,0 @@ "engines": { |
@@ -14,6 +14,6 @@ # dynamic-reverse-proxy | ||
if (req.url.match(/^\/register/i)) { | ||
proxy.registerRouteRequest(req, res); | ||
dynamicProxy.registerRouteRequest(req, res); | ||
} | ||
else { | ||
proxy.proxyRequest(req, res); | ||
dynamicProxy.proxyRequest(req, res); | ||
} | ||
@@ -95,2 +95,2 @@ }); | ||
} | ||
``` | ||
``` |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
7810
6
134
95
+ Addedeventemitter3@5.0.1(transitive)
+ Addedhttp-proxy@1.1.4(transitive)
- Removedcolors@0.6.2(transitive)
- Removedhttp-proxy@0.8.5(transitive)
- Removedoptimist@0.3.7(transitive)
- Removedpkginfo@0.2.3(transitive)
- Removedwordwrap@0.0.3(transitive)
Updatedhttp-proxy@1.1.4