node-tcp-proxy
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"main": "index.js", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -44,1 +44,10 @@ # node-tcp-proxy [![Build Status](https://semaphoreci.com/api/v1/tewarid/node-tcp-proxy/branches/master/badge.svg)](https://semaphoreci.com/tewarid/node-tcp-proxy) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/3e3d035c4b78445bbec6fb348cf027e1)](https://www.codacy.com/app/tewarid/node-tcp-proxy?utm_source=github.com&utm_medium=referral&utm_content=tewarid/node-tcp-proxy&utm_campaign=Badge_Grade) [![Maintainability](https://api.codeclimate.com/v1/badges/119038e281e93a7d5d05/maintainability)](https://codeclimate.com/github/tewarid/node-tcp-proxy/maintainability) | ||
`hostname` can be provided through an optional fourth parameter e.g. `{hostname: 0.0.0.0}` to `createProxy`. Console output may be silenced by adding `quiet: true` e.g. `{hostname: 0.0.0.0, quiet: true}`. | ||
If you specify more than one service host and port pair, the proxy will perform round-robin load balancing | ||
```javascript | ||
var hosts = ["host1", "host2"]; | ||
var ports = [10080, 10080]; | ||
var newProxy = proxy.createProxy(8080, hosts, ports); | ||
// or var newProxy = proxy.createProxy(8080, "host1,host2", "10080,10080"); | ||
``` |
@@ -41,3 +41,4 @@ #!/usr/bin/env node | ||
process.on("uncaughtException", function(err) { | ||
console.error(err); | ||
proxy.end(); | ||
}); | ||
@@ -44,0 +45,0 @@ |
@@ -15,6 +15,16 @@ var net = require("net"); | ||
function parse(o) { | ||
if (typeof o === "string") { | ||
return o.split(","); | ||
} else if (Array.isArray(o)) { | ||
return o; | ||
} else { | ||
throw new Error("cannot parse object: " + o); | ||
} | ||
} | ||
function TcpProxy(proxyPort, serviceHost, servicePort, options) { | ||
this.proxyPort = proxyPort; | ||
this.serviceHosts = serviceHost.split(","); | ||
this.servicePorts = servicePort.split(","); | ||
this.serviceHosts = parse(serviceHost); | ||
this.servicePorts = parse(servicePort); | ||
this.serviceHostIndex = -1; | ||
@@ -21,0 +31,0 @@ if (options === undefined) { |
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
13680
193
53