@@ -366,37 +366,40 @@ function Server(compiler, options) {
366
366
} ;
367
367
}
368
368
369
- // Use a self-signed certificate if no certificate was configured.
370
- // Cycle certs every 24 hours
371
- const certPath = path . join ( __dirname , "../ssl/server.pem" ) ;
372
- let certExists = fs . existsSync ( certPath ) ;
373
-
374
- if ( certExists ) {
375
- const certStat = fs . statSync ( certPath ) ;
376
- const certTtl = 1000 * 60 * 60 * 24 ;
377
- const now = new Date ( ) ;
378
-
379
- // cert is more than 30 days old, kill it with fire
380
- if ( ( now - certStat . ctime ) / certTtl > 30 ) {
381
- console . log ( "SSL Certificate is more than 30 days old. Removing." ) ;
382
- del . sync ( [ certPath ] , { force : true } ) ;
383
- certExists = false ;
369
+ let fakeCert ;
370
+ if ( ! options . https . key || ! options . https . cert ) {
371
+ // Use a self-signed certificate if no certificate was configured.
372
+ // Cycle certs every 24 hours
373
+ const certPath = path . join ( __dirname , "../ssl/server.pem" ) ;
374
+ let certExists = fs . existsSync ( certPath ) ;
375
+
376
+ if ( certExists ) {
377
+ const certStat = fs . statSync ( certPath ) ;
378
+ const certTtl = 1000 * 60 * 60 * 24 ;
379
+ const now = new Date ( ) ;
380
+
381
+ // cert is more than 30 days old, kill it with fire
382
+ if ( ( now - certStat . ctime ) / certTtl > 30 ) {
383
+ console . log ( "SSL Certificate is more than 30 days old. Removing." ) ;
384
+ del . sync ( [ certPath ] , { force : true } ) ;
385
+ certExists = false ;
386
+ }
384
387
}
385
- }
386
388
387
- if ( ! certExists ) {
388
- console . log ( "Generating SSL Certificate" ) ;
389
- const attrs = [ { name : "commonName" , value : "localhost" } ] ;
390
- const pems = selfsigned . generate ( attrs , {
391
- algorithm : "sha256" ,
392
- days : 30 ,
393
- keySize : 2048
394
- } ) ;
389
+ if ( ! certExists ) {
390
+ console . log ( "Generating SSL Certificate" ) ;
391
+ const attrs = [ { name : "commonName" , value : "localhost" } ] ;
392
+ const pems = selfsigned . generate ( attrs , {
393
+ algorithm : "sha256" ,
394
+ days : 30 ,
395
+ keySize : 2048
396
+ } ) ;
395
397
396
- fs . writeFileSync ( certPath , pems . private + pems . cert , { encoding : "utf-8" } ) ;
398
+ fs . writeFileSync ( certPath , pems . private + pems . cert , { encoding : "utf-8" } ) ;
399
+ }
400
+ fakeCert = fs . readFileSync ( certPath ) ;
397
401
}
398
402
399
- const fakeCert = fs . readFileSync ( certPath ) ;
400
403
options . https . key = options . https . key || fakeCert ;
401
404
options . https . cert = options . https . cert || fakeCert ;
402
405
0 commit comments