@@ -32,16 +32,16 @@ const app = express()
3232app . set ( 'json spaces' , 2 ) ;
3333app . set ( 'trust proxy' , [ 'loopback' , 'linklocal' , 'uniquelocal' ] ) ;
3434
35- if ( PROMETHEUS_ENABLED === 'true' ) {
35+ if ( PROMETHEUS_ENABLED === 'true' ) {
3636 app . use ( metricsMiddleware ) ;
3737}
3838
39- if ( process . env . DISABLE_REQUEST_LOGS !== 'true' ) {
39+ if ( process . env . DISABLE_REQUEST_LOGS !== 'true' ) {
4040 app . use ( morgan ( 'combined' ) ) ;
4141}
4242
43- app . use ( function ( req , res , next ) {
44- req . pipe ( concat ( function ( data ) {
43+ app . use ( function ( req , res , next ) {
44+ req . pipe ( concat ( function ( data ) {
4545
4646 if ( req . get ( "Content-Encoding" ) === "gzip" ) {
4747 req . body = zlib . gunzipSync ( data ) . toString ( 'utf8' ) ;
@@ -54,10 +54,10 @@ app.use(function (req, res, next) {
5454} ) ;
5555//Handle all paths
5656app . all ( '*' , ( req , res ) => {
57-
58- if ( process . env . OVERRIDE_RESPONSE_BODY_FILE_PATH ) {
57+
58+ if ( process . env . OVERRIDE_RESPONSE_BODY_FILE_PATH ) {
5959 // Path is relative to current directory
60- res . sendFile ( process . env . OVERRIDE_RESPONSE_BODY_FILE_PATH , { root : __dirname } ) ;
60+ res . sendFile ( process . env . OVERRIDE_RESPONSE_BODY_FILE_PATH , { root : __dirname } ) ;
6161 return ;
6262 }
6363
@@ -83,35 +83,35 @@ app.all('*', (req, res) => {
8383 }
8484 } ;
8585
86- if ( process . env . PRESERVE_HEADER_CASE ) {
87- let newHeaders = { ...req . headers } ;
86+ if ( process . env . PRESERVE_HEADER_CASE ) {
87+ let newHeaders = { ...req . headers } ;
8888
8989 // req.headers is in lowercase, processed, deduplicated. req.rawHeaders is not.
9090 // Match on the preserved case of the header name, populate newHeaders with preserved case and processed value.
9191 for ( let i = 0 ; i < req . rawHeaders . length ; i += 2 ) {
9292 let preservedHeaderName = req . rawHeaders [ i ] ;
9393 if ( preservedHeaderName == preservedHeaderName . toLowerCase ( ) ) { continue ; }
94-
94+
9595 newHeaders [ preservedHeaderName ] = req . header ( preservedHeaderName ) ;
9696 delete newHeaders [ preservedHeaderName . toLowerCase ( ) ] ;
9797 }
9898 echo . headers = newHeaders ;
9999 }
100-
100+
101101
102102 //Add client certificate details to the output, if present
103103 //This only works if `requestCert` is true when starting the server.
104- if ( req . socket . getPeerCertificate ) {
104+ if ( req . socket . getPeerCertificate ) {
105105 echo . clientCertificate = req . socket . getPeerCertificate ( ) ;
106106 }
107107
108108 //Include visible environment variables
109- if ( process . env . ECHO_INCLUDE_ENV_VARS ) {
109+ if ( process . env . ECHO_INCLUDE_ENV_VARS ) {
110110 echo . env = process . env ;
111111 }
112112
113113 //If the Content-Type of the incoming body `is` JSON, it can be parsed and returned in the body
114- if ( req . is ( 'application/json' ) ) {
114+ if ( req . is ( 'application/json' ) ) {
115115 try {
116116 echo . json = JSON . parse ( req . body )
117117 } catch ( error ) {
@@ -126,7 +126,7 @@ app.all('*', (req, res) => {
126126 echo . jwt = token ;
127127 } else {
128128 token = token . split ( " " ) . pop ( ) ;
129- const decoded = jwt . decode ( token , { complete : true } ) ;
129+ const decoded = jwt . decode ( token , { complete : true } ) ;
130130 echo . jwt = decoded ;
131131 }
132132 }
@@ -144,12 +144,12 @@ app.all('*', (req, res) => {
144144 //Set the response content type to what the user wants
145145 const setResponseContentType = req . headers [ "x-set-response-content-type" ] || req . query [ "x-set-response-content-type" ] ;
146146
147- if ( setResponseContentType ) {
147+ if ( setResponseContentType ) {
148148 res . contentType ( setResponseContentType ) ;
149149 }
150150
151151 //Set the CORS policy
152- if ( process . env . CORS_ALLOW_ORIGIN ) {
152+ if ( process . env . CORS_ALLOW_ORIGIN ) {
153153 res . header ( 'Access-Control-Allow-Origin' , process . env . CORS_ALLOW_ORIGIN ) ;
154154 if ( process . env . CORS_ALLOW_METHODS ) {
155155 res . header ( 'Access-Control-Allow-Methods' , process . env . CORS_ALLOW_METHODS ) ;
@@ -163,7 +163,7 @@ app.all('*', (req, res) => {
163163 }
164164
165165 //Ability to send an empty response back
166- if ( process . env . ECHO_BACK_TO_CLIENT != undefined && process . env . ECHO_BACK_TO_CLIENT == "false" ) {
166+ if ( process . env . ECHO_BACK_TO_CLIENT != undefined && process . env . ECHO_BACK_TO_CLIENT == "false" ) {
167167 res . end ( ) ;
168168 }
169169 //Ability to send just the request body in the response, nothing else
@@ -179,7 +179,7 @@ app.all('*', (req, res) => {
179179 if ( ! process . env . LOG_IGNORE_PATH || ! new RegExp ( process . env . LOG_IGNORE_PATH ) . test ( req . path ) ) {
180180
181181 let spacer = 4 ;
182- if ( process . env . LOG_WITHOUT_NEWLINE ) {
182+ if ( process . env . LOG_WITHOUT_NEWLINE ) {
183183 spacer = null ;
184184 }
185185
@@ -201,36 +201,36 @@ let httpsOpts = {
201201} ;
202202
203203//Whether to enable the client certificate feature
204- if ( process . env . MTLS_ENABLE ) {
205- httpsOpts = {
206- requestCert : true ,
207- rejectUnauthorized : false ,
208- ...httpsOpts
209- }
204+ if ( process . env . MTLS_ENABLE ) {
205+ httpsOpts = {
206+ requestCert : true ,
207+ rejectUnauthorized : false ,
208+ ...httpsOpts
209+ }
210210}
211211
212212var httpServer = http . createServer ( httpOpts , app ) . listen ( process . env . HTTP_PORT || 8080 ) ;
213- var httpsServer = https . createServer ( httpsOpts , app ) . listen ( process . env . HTTPS_PORT || 8443 ) ;
213+ var httpsServer = https . createServer ( httpsOpts , app ) . listen ( process . env . HTTPS_PORT || 8443 ) ;
214214console . log ( `Listening on ports ${ process . env . HTTP_PORT || 8080 } for http, and ${ process . env . HTTPS_PORT || 8443 } for https.` ) ;
215215
216216let calledClose = false ;
217217
218218process . on ( 'exit' , function ( ) {
219219 if ( calledClose ) return ;
220220 console . log ( 'Got exit event. Trying to stop Express server.' ) ;
221- server . close ( function ( ) {
221+ server . close ( function ( ) {
222222 console . log ( "Express server closed" ) ;
223223 } ) ;
224224} ) ;
225225
226226process . on ( 'SIGINT' , shutDown ) ;
227227process . on ( 'SIGTERM' , shutDown ) ;
228228
229- function shutDown ( ) {
229+ function shutDown ( ) {
230230 console . log ( 'Got a kill signal. Trying to exit gracefully.' ) ;
231231 calledClose = true ;
232- httpServer . close ( function ( ) {
233- httpsServer . close ( function ( ) {
232+ httpServer . close ( function ( ) {
233+ httpsServer . close ( function ( ) {
234234 console . log ( "HTTP and HTTPS servers closed. Asking process to exit." ) ;
235235 process . exit ( )
236236 } ) ;
0 commit comments