@@ -15,7 +15,8 @@ const certOptions = {
1515 cert : fs . readFileSync ( path . resolve ( __dirname , "cert/server.crt" ) )
1616}
1717
18- const port = process . env . PORT || 443
18+ const port = process . env . PORT ||
19+ /* istanbul ignore next: impossible to test */ 443
1920
2021// run express
2122const app = express ( )
@@ -26,18 +27,19 @@ app.use(compression())
2627app . set ( "json spaces" , 0 )
2728
2829// redirect http to https
29- /* istanbul ignore else */ // useless to test
30- if ( port === 443 )
30+ /* istanbul ignore else: useless to test */
31+ if ( port === 443 || process . env . HTTP_PORT )
3132 app . http = http . createServer ( ( req , res ) => {
3233 res . writeHead ( 301 , { Location : "https://" + req . headers [ "host" ] + req . url } )
3334 res . end ( )
34- } ) . listen ( 80 )
35+ } ) . listen ( process . env . HTTP_PORT ||
36+ /* istanbul ignore next: impossible to test */ 80 )
3537
3638// serve static files, if launched as: "node index.js <static-path>"
37- /* istanbul ignore else */ // useless to test
39+ /* istanbul ignore else: useless to test */
3840if ( require . main === module || process . env . USE_STATIC ) {
3941 let staticPath = process . cwd ( )
40- /* istanbul ignore if */ // impossible to test
42+ /* istanbul ignore if: impossible to test */
4143 if ( process . argv . join ( ) . includes ( "serve" ) )
4244 staticPath = process . argv . join ( ) . replace ( "sudo" , "" )
4345 . replace ( "serve" , "" ) . replace ( " " , "" )
0 commit comments