@@ -79,9 +79,9 @@ exports.createServer = function () {
7979 case 'number' : port = arg ; break ;
8080 case 'object' : options = arg || { } ; break ;
8181 case 'function' : callback = arg ; handlers . push ( callback ) ; break ;
82- } ;
82+ }
8383 } ) ;
84-
84+
8585 //
8686 // Helper function to create intelligent error message(s)
8787 // for the very liberal arguments parsing performed by
@@ -90,36 +90,35 @@ exports.createServer = function () {
9090 function validArguments ( ) {
9191 var conditions = {
9292 'port and host' : function ( ) {
93- return port && host ;
93+ return port && host ;
9494 } ,
9595 'options.target or options.router' : function ( ) {
96- return options && ( options . router ||
96+ return options && ( options . router ||
9797 ( options . target && options . target . host && options . target . port ) ) ;
9898 } ,
9999 'or proxy handlers' : function ( ) {
100100 return handlers && handlers . length ;
101101 }
102- }
103-
102+ } ;
103+
104104 var missing = Object . keys ( conditions ) . filter ( function ( name ) {
105105 return ! conditions [ name ] ( ) ;
106106 } ) ;
107-
107+
108108 if ( missing . length === 3 ) {
109109 message = 'Cannot proxy without ' + missing . join ( ', ' ) ;
110110 return false ;
111111 }
112-
112+
113113 return true ;
114- }
115-
114+ }
115+
116116 if ( ! validArguments ( ) ) {
117117 //
118- // If `host`, `port` and `options` are all not passed (with valid
118+ // If `host`, `port` and `options` are all not passed (with valid
119119 // options) then this server is improperly configured.
120120 //
121121 throw new Error ( message ) ;
122- return ;
123122 }
124123
125124 //
@@ -130,7 +129,7 @@ exports.createServer = function () {
130129 options . target = options . target || { } ;
131130 options . target . port = options . target . port || port ;
132131 options . target . host = options . target . host || host ;
133-
132+
134133 if ( options . target && options . target . host && options . target . port ) {
135134 //
136135 // If an explicit `host` and `port` combination has been passed
@@ -148,31 +147,31 @@ exports.createServer = function () {
148147 // we have to assume that this is a "go-anywhere" Proxy (i.e. a `RoutingProxy`).
149148 //
150149 proxy = new RoutingProxy ( options ) ;
151-
150+
152151 if ( options . router ) {
153152 //
154- // If a routing table has been supplied than we assume
153+ // If a routing table has been supplied than we assume
155154 // the user intends us to add the "proxy" middleware layer
156- // for them
155+ // for them
157156 //
158157 handlers . push ( function ( req , res ) {
159158 proxy . proxyRequest ( req , res ) ;
160159 } ) ;
161-
160+
162161 proxy . on ( 'routes' , function ( routes ) {
163162 server . emit ( 'routes' , routes ) ;
164163 } ) ;
165- }
164+ }
166165 }
167-
166+
168167 //
169168 // Create the `http[s].Server` instance which will use
170169 // an instance of `httpProxy.HttpProxy`.
171170 //
172- handler = handlers . length > 1
171+ handler = handlers . length > 1
173172 ? exports . stack ( handlers , proxy )
174173 : function ( req , res ) { handlers [ 0 ] ( req , res , proxy ) } ;
175-
174+
176175 server = options . https
177176 ? https . createServer ( options . https , handler )
178177 : http . createServer ( handler ) ;
@@ -184,8 +183,8 @@ exports.createServer = function () {
184183 if ( ! callback ) {
185184 //
186185 // If an explicit callback has not been supplied then
187- // automagically proxy the request using the `HttpProxy`
188- // instance we have created.
186+ // automagically proxy the request using the `HttpProxy`
187+ // instance we have created.
189188 //
190189 server . on ( 'upgrade' , function ( req , socket , head ) {
191190 proxy . proxyWebSocketRequest ( req , socket , head ) ;
@@ -222,7 +221,7 @@ exports.createServer = function () {
222221//
223222exports . buffer = function ( obj ) {
224223 var events = [ ] ,
225- onData ,
224+ onData ,
226225 onEnd ;
227226
228227 obj . on ( 'data' , onData = function ( data , encoding ) {
@@ -240,11 +239,11 @@ exports.buffer = function (obj) {
240239 } ,
241240 destroy : function ( ) {
242241 this . end ( ) ;
243- this . resume = function ( ) {
244- console . error ( "Cannot resume buffer after destroying it." ) ;
245- } ;
246-
247- onData = onEnd = events = obj = null ;
242+ this . resume = function ( ) {
243+ console . error ( "Cannot resume buffer after destroying it." ) ;
244+ } ;
245+
246+ onData = onEnd = events = obj = null ;
248247 } ,
249248 resume : function ( ) {
250249 this . end ( ) ;
@@ -278,10 +277,10 @@ exports.setMaxSockets = function (value) {
278277//
279278// ### function stack (middlewares, proxy)
280279// #### @middlewares {Array} Array of functions to stack.
281- // #### @proxy {HttpProxy|RoutingProxy} Proxy instance to
280+ // #### @proxy {HttpProxy|RoutingProxy} Proxy instance to
282281// Iteratively build up a single handler to the `http.Server`
283282// `request` event (i.e. `function (req, res)`) by wrapping
284- // each middleware `layer` into a `child` middleware which
283+ // each middleware `layer` into a `child` middleware which
285284// is in invoked by the parent (i.e. predecessor in the Array).
286285//
287286// adapted from https://github.com/creationix/stack
@@ -295,17 +294,17 @@ exports.stack = function stack (middlewares, proxy) {
295294 if ( err ) {
296295 if ( res . _headerSent ) {
297296 res . destroy ( ) ;
298- }
297+ }
299298 else {
300299 res . statusCode = 500 ;
301300 res . setHeader ( 'Content-Type' , 'text/plain' ) ;
302301 res . end ( 'Internal Server Error' ) ;
303302 }
304-
303+
305304 console . error ( 'Error in middleware(s): %s' , err . stack ) ;
306305 return ;
307306 }
308-
307+
309308 if ( child ) {
310309 child ( req , res ) ;
311310 }
@@ -344,29 +343,29 @@ exports._getAgent = function _getAgent (options) {
344343 if ( ! options || ! options . host ) {
345344 throw new Error ( '`options.host` is required to create an Agent.' ) ;
346345 }
347-
346+
348347 if ( ! options . port ) {
349348 options . port = options . https ? 443 : 80 ;
350349 }
351350
352351 var Agent = options . https ? https . Agent : http . Agent ,
353352 agent ;
354353
355- agent = new Agent ( {
356- host : options . host ,
354+ agent = new Agent ( {
355+ host : options . host ,
357356 port : options . port
358357 } ) ;
359358
360359 agent . maxSockets = options . maxSockets || maxSockets ;
361360
362361 return agent ;
363- }
362+ } ;
364363
365364//
366365// ### function _getProtocol (options)
367366// #### @options {Object} Options for the proxy target.
368- // Returns the appropriate node.js core protocol module (i.e. `http` or `https`)
369- // based on the `options` supplied.
367+ // Returns the appropriate node.js core protocol module (i.e. `http` or `https`)
368+ // based on the `options` supplied.
370369//
371370exports . _getProtocol = function _getProtocol ( options ) {
372371 return options . https ? https : http ;
@@ -382,7 +381,7 @@ exports._getProtocol = function _getProtocol (options) {
382381//
383382exports . _getBase = function _getBase ( options ) {
384383 var result = function ( ) { } ;
385-
384+
386385 if ( options . https && typeof options . https === 'object' ) {
387386 [ 'ca' , 'cert' , 'key' ] . forEach ( function ( key ) {
388387 if ( options . https [ key ] ) {
0 commit comments