@@ -9,9 +9,6 @@ var https = require("https");
99var http = require ( "http" ) ;
1010var opn = require ( "opn" ) ;
1111
12- const useHttps = argv . ssl || argv . https ;
13-
14- var server ;
1512
1613const NO_PATH_FILE_ERROR_MESSAGE =
1714 "Error: index.html could not be found in the specified path " ;
@@ -37,20 +34,35 @@ if (argv.config) {
3734 argv = Object . assign ( { } , config , argv ) ;
3835}
3936
37+ const useHttps = argv . ssl || argv . https ;
38+
4039// As a part of the startup - check to make sure we can access index.html
4140returnDistFile ( true ) ;
4241
43- // Start with with/without https
42+ // Start with/without https
43+ let server ;
4444if ( useHttps ) {
45- pem . createCertificate ( { days : 1 , selfSigned : true } , function ( err , keys ) {
46- var options = {
45+ const startSSLCallback = ( err , keys ) => {
46+ if ( err ) {
47+ throw err ;
48+ }
49+
50+ const options = {
4751 key : keys . serviceKey ,
4852 cert : keys . certificate ,
4953 rejectUnauthorized : false
5054 } ;
5155 server = https . createServer ( options , requestListener ) ;
5256 start ( ) ;
53- } ) ;
57+ } ;
58+
59+ if ( argv . key && argv . cert ) {
60+ const serviceKey = fs . readFileSync ( argv . key ) ;
61+ const certificate = fs . readFileSync ( argv . cert ) ;
62+ startSSLCallback ( null , { serviceKey, certificate } ) ;
63+ } else {
64+ pem . createCertificate ( { days : 1 , selfSigned : true } , startSSLCallback ) ;
65+ }
5466} else {
5567 server = http . createServer ( requestListener ) ;
5668 start ( ) ;
0 commit comments