@@ -3,6 +3,7 @@ var sha1 = require('node-sha1');
33var util = require ( 'util' ) ;
44var EventSource = require ( './eventsource' ) ;
55var pointer = require ( 'json-pointer' ) ;
6+ var global_tunnel = require ( 'global-tunnel' ) ;
67var VERSION = "1.4.0" ;
78
89var 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
0 commit comments