@@ -23,7 +23,7 @@ var http = require("http"),
23
23
function bound ( that , method ) {
24
24
// bind a method, to ensure `this=that` when it is called
25
25
// because prototype languages are bad
26
- return function ( ) {
26
+ return function ( ) {
27
27
return method . apply ( that , arguments ) ;
28
28
} ;
29
29
}
@@ -50,13 +50,13 @@ function fail(req, res, code, msg) {
50
50
function jsonHandler ( handler ) {
51
51
// wrap json handler, so the handler is called with parsed data,
52
52
// rather than implementing streaming parsing in the handler itself
53
- return function ( req , res ) {
53
+ return function ( req , res ) {
54
54
var args = argumentsArray ( arguments ) ;
55
55
var buf = "" ;
56
- req . on ( "data" , function ( chunk ) {
56
+ req . on ( "data" , function ( chunk ) {
57
57
buf += chunk ;
58
58
} ) ;
59
- req . on ( "end" , function ( ) {
59
+ req . on ( "end" , function ( ) {
60
60
var data ;
61
61
try {
62
62
data = JSON . parse ( buf ) || { } ;
@@ -72,7 +72,7 @@ function jsonHandler(handler) {
72
72
73
73
function authorized ( method ) {
74
74
// decorator for token-authorized handlers
75
- return function ( req , res ) {
75
+ return function ( req , res ) {
76
76
if ( ! this . authToken ) {
77
77
return method . apply ( this , arguments ) ;
78
78
}
@@ -105,8 +105,8 @@ function parseHost(req) {
105
105
function camelCaseify ( options ) {
106
106
// camelCaseify options dict, for backward compatibility
107
107
let camelOptions = { } ;
108
- Object . keys ( options ) . forEach ( key => {
109
- const camelKey = key . replace ( / _ ( .) / g, function ( match , part , offset , string ) {
108
+ Object . keys ( options ) . forEach ( ( key ) => {
109
+ const camelKey = key . replace ( / _ ( .) / g, function ( match , part , offset , string ) {
110
110
return part . toUpperCase ( ) ;
111
111
} ) ;
112
112
if ( camelKey !== key ) {
@@ -117,7 +117,7 @@ function camelCaseify(options) {
117
117
return camelOptions ;
118
118
}
119
119
120
- const loadStorage = options => {
120
+ const loadStorage = ( options ) => {
121
121
if ( options . storageBackend ) {
122
122
const BackendStorageClass = require ( options . storageBackend ) ;
123
123
return new BackendStorageClass ( options ) ;
@@ -158,14 +158,14 @@ class ConfigurableProxy extends EventEmitter {
158
158
// Mock the statsd object, rather than pepper the codebase with
159
159
// null checks. FIXME: Maybe use a JS Proxy object (if available?)
160
160
this . statsd = {
161
- increment : function ( ) { } ,
162
- decrement : function ( ) { } ,
163
- timing : function ( ) { } ,
164
- gauge : function ( ) { } ,
165
- set : function ( ) { } ,
166
- createTimer : function ( ) {
161
+ increment : function ( ) { } ,
162
+ decrement : function ( ) { } ,
163
+ timing : function ( ) { } ,
164
+ gauge : function ( ) { } ,
165
+ set : function ( ) { } ,
166
+ createTimer : function ( ) {
167
167
return {
168
- stop : function ( ) { } ,
168
+ stop : function ( ) { } ,
169
169
} ;
170
170
} ,
171
171
} ;
@@ -193,8 +193,8 @@ class ConfigurableProxy extends EventEmitter {
193
193
] ,
194
194
] ;
195
195
196
- var logErrors = handler => {
197
- return function ( req , res ) {
196
+ var logErrors = ( handler ) => {
197
+ return function ( req , res ) {
198
198
function logError ( e ) {
199
199
that . log . error ( "Error in handler for " + req . method + " " + req . url + ": %s" , e ) ;
200
200
}
@@ -227,7 +227,7 @@ class ConfigurableProxy extends EventEmitter {
227
227
// proxy websockets
228
228
this . proxyServer . on ( "upgrade" , bound ( this , this . handleProxyWs ) ) ;
229
229
230
- this . proxy . on ( "proxyRes" , function ( proxyRes , req , res ) {
230
+ this . proxy . on ( "proxyRes" , function ( proxyRes , req , res ) {
231
231
that . statsd . increment ( "requests." + proxyRes . statusCode , 1 ) ;
232
232
} ) ;
233
233
}
@@ -267,7 +267,7 @@ class ConfigurableProxy extends EventEmitter {
267
267
// remove a route from the routing table
268
268
var routes = this . _routes ;
269
269
270
- return routes . get ( path ) . then ( result => {
270
+ return routes . get ( path ) . then ( ( result ) => {
271
271
if ( result ) {
272
272
this . log . info ( "Removing route %s" , path ) ;
273
273
return routes . remove ( path ) ;
@@ -278,7 +278,7 @@ class ConfigurableProxy extends EventEmitter {
278
278
getRoute ( req , res , path ) {
279
279
// GET a single route
280
280
path = this . _routes . cleanPath ( path ) ;
281
- return this . _routes . get ( path ) . then ( function ( route ) {
281
+ return this . _routes . get ( path ) . then ( function ( route ) {
282
282
if ( ! route ) {
283
283
res . writeHead ( 404 ) ;
284
284
res . end ( ) ;
@@ -319,11 +319,11 @@ class ConfigurableProxy extends EventEmitter {
319
319
}
320
320
res . writeHead ( 200 , { "Content-Type" : "application/json" } ) ;
321
321
322
- return this . _routes . getAll ( ) . then ( routes => {
322
+ return this . _routes . getAll ( ) . then ( ( routes ) => {
323
323
var results = { } ;
324
324
325
325
if ( inactiveSince ) {
326
- Object . keys ( routes ) . forEach ( function ( path ) {
326
+ Object . keys ( routes ) . forEach ( function ( path ) {
327
327
if ( routes [ path ] . last_activity < inactiveSince ) {
328
328
results [ path ] = routes [ path ] ;
329
329
}
@@ -349,7 +349,7 @@ class ConfigurableProxy extends EventEmitter {
349
349
}
350
350
351
351
var that = this ;
352
- return this . addRoute ( path , data ) . then ( function ( ) {
352
+ return this . addRoute ( path , data ) . then ( function ( ) {
353
353
res . writeHead ( 201 ) ;
354
354
res . end ( ) ;
355
355
that . statsd . increment ( "api.route.add" , 1 ) ;
@@ -359,7 +359,7 @@ class ConfigurableProxy extends EventEmitter {
359
359
deleteRoutes ( req , res , path ) {
360
360
// DELETE removes an existing route
361
361
362
- return this . _routes . get ( path ) . then ( result => {
362
+ return this . _routes . get ( path ) . then ( ( result ) => {
363
363
var p , code ;
364
364
if ( result ) {
365
365
p = this . removeRoute ( path ) ;
@@ -382,7 +382,7 @@ class ConfigurableProxy extends EventEmitter {
382
382
var basePath = this . hostRouting ? "/" + parseHost ( req ) : "" ;
383
383
var path = basePath + decodeURIComponent ( URL . parse ( req . url ) . pathname ) ;
384
384
385
- return this . _routes . getTarget ( path ) . then ( function ( route ) {
385
+ return this . _routes . getTarget ( path ) . then ( function ( route ) {
386
386
timer . stop ( ) ;
387
387
if ( route ) {
388
388
return {
@@ -399,7 +399,7 @@ class ConfigurableProxy extends EventEmitter {
399
399
400
400
return routes
401
401
. get ( prefix )
402
- . then ( function ( result ) {
402
+ . then ( function ( result ) {
403
403
if ( result ) {
404
404
return routes . update ( prefix , { last_activity : new Date ( ) } ) ;
405
405
}
@@ -448,20 +448,20 @@ class ConfigurableProxy extends EventEmitter {
448
448
urlSpec . pathname = urlSpec . pathname + code . toString ( ) ;
449
449
var secure = / h t t p s / gi. test ( urlSpec . protocol ) ? true : false ;
450
450
var url = URL . format ( urlSpec ) ;
451
- var errorRequest = ( secure ? https : http ) . request ( url , function ( upstream ) {
452
- [ "content-type" , "content-encoding" ] . map ( function ( key ) {
451
+ var errorRequest = ( secure ? https : http ) . request ( url , function ( upstream ) {
452
+ [ "content-type" , "content-encoding" ] . map ( function ( key ) {
453
453
if ( ! upstream . headers [ key ] ) return ;
454
454
if ( res . setHeader ) res . setHeader ( key , upstream . headers [ key ] ) ;
455
455
} ) ;
456
456
if ( res . writeHead ) res . writeHead ( code ) ;
457
- upstream . on ( "data" , data => {
457
+ upstream . on ( "data" , ( data ) => {
458
458
if ( res . write ) res . write ( data ) ;
459
459
} ) ;
460
460
upstream . on ( "end" , ( ) => {
461
461
if ( res . end ) res . end ( ) ;
462
462
} ) ;
463
463
} ) ;
464
- errorRequest . on ( "error" , e => {
464
+ errorRequest . on ( "error" , ( e ) => {
465
465
// custom error failed, fallback on default
466
466
this . log . error ( "Failed to get custom error page: %s" , e ) ;
467
467
this . _handleProxyErrorDefault ( code , kind , req , res ) ;
@@ -504,16 +504,15 @@ class ConfigurableProxy extends EventEmitter {
504
504
var args = Array . prototype . slice . call ( arguments , 1 ) ;
505
505
506
506
// get the proxy target
507
- return this . targetForReq ( req ) . then ( match => {
507
+ return this . targetForReq ( req ) . then ( ( match ) => {
508
508
if ( ! match ) {
509
509
that . handleProxyError ( 404 , kind , req , res ) ;
510
510
return ;
511
511
}
512
512
513
513
if ( kind === "web" ) {
514
514
that . emit ( "proxyRequest" , req , res ) ;
515
- }
516
- else {
515
+ } else {
517
516
that . emit ( "proxyRequestWs" , req , res , args [ 2 ] ) ;
518
517
}
519
518
var prefix = match . prefix ;
@@ -534,7 +533,7 @@ class ConfigurableProxy extends EventEmitter {
534
533
args . push ( { target : target } ) ;
535
534
536
535
// add error handling
537
- args . push ( function ( e ) {
536
+ args . push ( function ( e ) {
538
537
that . handleProxyError ( 503 , kind , req , res , e ) ;
539
538
} ) ;
540
539
@@ -544,11 +543,11 @@ class ConfigurableProxy extends EventEmitter {
544
543
that . proxy [ kind ] . apply ( that . proxy , args ) ;
545
544
546
545
// update timestamp on any request/reply data as well (this includes websocket data)
547
- req . on ( "data" , function ( ) {
546
+ req . on ( "data" , function ( ) {
548
547
that . updateLastActivity ( prefix ) ;
549
548
} ) ;
550
549
551
- res . on ( "data" , function ( ) {
550
+ res . on ( "data" , function ( ) {
552
551
that . updateLastActivity ( prefix ) ;
553
552
} ) ;
554
553
0 commit comments