Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 4898198

Browse files
committed
Merge pull request #19 from launchdarkly/jko/proxy
Add support for optional reverse proxy configuration
2 parents 4965c67 + e248e44 commit 4898198

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

.hound.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
asi: false,
3+
bitwise: true,
4+
browser: true,
5+
camelcase: false,
6+
curly: true,
7+
forin: true,
8+
immed: true,
9+
latedef: "nofunc",
10+
maxlen: 80,
11+
newcap: true,
12+
noarg: true,
13+
noempty: true,
14+
nonew: true,
15+
predef: [
16+
"$",
17+
"jQuery",
18+
"jasmine",
19+
"beforeEach",
20+
"describe",
21+
"expect",
22+
"it",
23+
"angular",
24+
"inject",
25+
"module"
26+
],
27+
quotmark: true,
28+
trailing: true,
29+
undef: true,
30+
unused: true
31+
}

index.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var sha1 = require('node-sha1');
33
var util = require('util');
44
var EventSource = require('./eventsource');
55
var pointer = require('json-pointer');
6+
var global_tunnel = require('global-tunnel');
67
var VERSION = "1.4.0";
78

89
var noop = function(){};
@@ -23,6 +24,18 @@ var new_client = function(api_key, config) {
2324
client.api_key = api_key;
2425
client.queue = [];
2526
client.offline = false;
27+
client.proxy_host = config.proxy_host;
28+
client.proxy_port = config.proxy_port;
29+
client.proxy_auth = config.proxy_auth;
30+
31+
// Initialize global tunnel if proxy options are set
32+
if (client.proxy_host && client.proxy_port) {
33+
global_tunnel.initialize({
34+
host: client.proxy_host,
35+
port: client.proxy_port,
36+
proxyAuth: client.proxy_auth
37+
});
38+
}
2639

2740
if (!api_key) {
2841
throw new Error("You must configure the client with an API key");
@@ -106,15 +119,17 @@ var new_client = function(api_key, config) {
106119
client.toggle = function(key, user, default_val, fn) {
107120
var cb = fn || noop;
108121

122+
var request_params = {
123+
method: "GET",
124+
headers: {
125+
'Authorization': 'api_key ' + this.api_key,
126+
'User-Agent': 'NodeJSClient/' + VERSION
127+
},
128+
timeout: this.timeout * 1000
129+
};
130+
109131
var make_request = (function(cb, err_cb) {
110-
requestify.request(this.base_uri + '/api/eval/features/' + key, {
111-
method: "GET",
112-
headers: {
113-
'Authorization': 'api_key ' + this.api_key,
114-
'User-Agent': 'NodeJSClient/' + VERSION
115-
},
116-
timeout: this.timeout * 1000
117-
})
132+
requestify.request(this.base_uri + '/api/eval/features/' + key, request_params)
118133
.then(cb, err_cb);
119134
}).bind(this);
120135

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"json-pointer": "^0.3.0",
2525
"node-sha1": "0.0.1",
2626
"original": "~0.0.8",
27-
"requestify": "~0.1.16"
27+
"requestify": "~0.1.16",
28+
"global-tunnel": "https://github.com/launchdarkly/global-tunnel/tarball/30cdde93903d9d1e4beac3727cf20e9a8d2e0ccf"
2829
},
2930
"engines": {
3031
"node": ">= 0.8.x"

0 commit comments

Comments
 (0)