67
67
"--redirect-port <redirect-port>" ,
68
68
"Redirect HTTP requests on this port to the server on HTTPS"
69
69
)
70
- . option (
71
- "--redirect-to <port>" ,
72
- "Redirect HTTP requests from --redirect-port to this port" )
70
+ . option ( "--redirect-to <port>" , "Redirect HTTP requests from --redirect-port to this port" )
73
71
. option ( "--pid-file <pid-file>" , "Write our PID to a file" )
74
72
// passthrough http-proxy options
75
73
. option ( "--no-x-forward" , "Don't add 'X-forward-' headers to proxied requests" )
84
82
. option (
85
83
"--custom-header <header>" ,
86
84
"Custom header to add to proxied requests. Use same option for multiple headers (--custom-header k1:v1 --custom-header k2:v2)" ,
87
- collectHeadersIntoObject , { }
85
+ collectHeadersIntoObject ,
86
+ { }
88
87
)
89
88
. option ( "--insecure" , "Disable SSL cert verification" )
90
89
. option ( "--host-routing" , "Use host routing (host as first level of path)" )
@@ -110,12 +109,12 @@ args
110
109
// collects multiple flags to an object
111
110
// --custom-header "k1:v1" --custom-header " k2 : v2 " --> {"k1":"v1","k2":"v2"}
112
111
function collectHeadersIntoObject ( value , previous ) {
113
- var headerParts = value . split ( ":" ) . map ( p => p . trim ( ) )
112
+ var headerParts = value . split ( ":" ) . map ( ( p ) => p . trim ( ) ) ;
114
113
if ( headerParts . length != 2 ) {
115
114
log . error ( "A single colon was expected in custom header: " + value ) ;
116
115
process . exit ( 1 ) ;
117
116
}
118
- previous [ headerParts [ 0 ] ] = headerParts [ 1 ]
117
+ previous [ headerParts [ 0 ] ] = headerParts [ 1 ] ;
119
118
}
120
119
121
120
args . parse ( process . argv ) ;
@@ -206,7 +205,7 @@ if (args.apiSslKey || args.apiSslCert) {
206
205
var chain = fs . readFileSync ( args . apiSslCa , "utf8" ) ;
207
206
var ca = [ ] ;
208
207
var cert = [ ] ;
209
- chain . split ( "\n" ) . forEach ( function ( line ) {
208
+ chain . split ( "\n" ) . forEach ( function ( line ) {
210
209
cert . push ( line ) ;
211
210
if ( line . match ( / - E N D C E R T I F I C A T E - / ) ) {
212
211
ca . push ( new Buffer ( cert . join ( "\n" ) ) ) ;
@@ -241,7 +240,7 @@ if (args.clientSslKey || args.clientSslCert) {
241
240
var chain = fs . readFileSync ( args . clientSslCa , "utf8" ) ;
242
241
var ca = [ ] ;
243
242
var cert = [ ] ;
244
- chain . split ( "\n" ) . forEach ( function ( line ) {
243
+ chain . split ( "\n" ) . forEach ( function ( line ) {
245
244
cert . push ( line ) ;
246
245
if ( line . match ( / - E N D C E R T I F I C A T E - / ) ) {
247
246
ca . push ( new Buffer ( cert . join ( "\n" ) ) ) ;
@@ -357,7 +356,7 @@ if (args.pidFile) {
357
356
var fd = fs . openSync ( args . pidFile , "w" ) ;
358
357
fs . writeSync ( fd , process . pid . toString ( ) ) ;
359
358
fs . closeSync ( fd ) ;
360
- process . on ( "exit" , function ( ) {
359
+ process . on ( "exit" , function ( ) {
361
360
log . debug ( "Removing %s" , args . pidFile ) ;
362
361
fs . unlinkSync ( args . pidFile ) ;
363
362
} ) ;
@@ -366,9 +365,9 @@ if (args.pidFile) {
366
365
// Redirect HTTP to HTTPS on the proxy's port
367
366
if ( options . redirectPort && listen . port !== 80 ) {
368
367
var http = require ( "http" ) ;
369
- var redirectPort = ( options . redirectTo ? options . redirectTo : listen . port ) ;
368
+ var redirectPort = options . redirectTo ? options . redirectTo : listen . port ;
370
369
var server = http
371
- . createServer ( function ( req , res ) {
370
+ . createServer ( function ( req , res ) {
372
371
var host = req . headers . host . split ( ":" ) [ 0 ] ;
373
372
374
373
// Make sure that when we redirect, it's to the port the proxy is running on
@@ -379,30 +378,29 @@ if (options.redirectPort && listen.port !== 80) {
379
378
res . writeHead ( 301 , { Location : "https://" + host + req . url } ) ;
380
379
res . end ( ) ;
381
380
} )
382
- . listen ( options . redirectPort , ( ) => {
383
- log . info ( "Added HTTP to HTTPS redirection from "
384
- + server . address ( ) . port
385
- + " to "
386
- + redirectPort ) ;
381
+ . listen ( options . redirectPort , ( ) => {
382
+ log . info (
383
+ "Added HTTP to HTTPS redirection from " + server . address ( ) . port + " to " + redirectPort
384
+ ) ;
387
385
} ) ;
388
386
}
389
387
390
388
// trigger normal exit on SIGINT
391
389
// without this, PID cleanup won't fire on SIGINT
392
- process . on ( "SIGINT" , function ( ) {
390
+ process . on ( "SIGINT" , function ( ) {
393
391
log . warn ( "Interrupted" ) ;
394
392
process . exit ( 2 ) ;
395
393
} ) ;
396
394
397
395
// trigger normal exit on SIGTERM
398
396
// fired on `docker stop` and during Kubernetes pod container evictions
399
- process . on ( "SIGTERM" , function ( ) {
397
+ process . on ( "SIGTERM" , function ( ) {
400
398
log . warn ( "Terminated" ) ;
401
399
process . exit ( 2 ) ;
402
400
} ) ;
403
401
404
402
// log uncaught exceptions, don't exit now that setup is complete
405
- process . on ( "uncaughtException" , function ( e ) {
403
+ process . on ( "uncaughtException" , function ( e ) {
406
404
log . error ( "Uncaught Exception: " + e . message ) ;
407
405
if ( e . stack ) {
408
406
log . error ( e . stack ) ;
0 commit comments