@@ -13,7 +13,7 @@ import { CliConfig } from '../models/config';
13
13
import { oneLine } from 'common-tags' ;
14
14
15
15
export default Task . extend ( {
16
- run : function ( commandOptions : ServeTaskOptions ) {
16
+ run : function ( commandOptions : ServeTaskOptions ) {
17
17
const ui = this . ui ;
18
18
19
19
let webpackCompiler : any ;
@@ -46,6 +46,20 @@ export default Task.extend({
46
46
}
47
47
}
48
48
49
+ let sslKey : string = null ;
50
+ let sslCert : string = null ;
51
+
52
+ if ( commandOptions . ssl ) {
53
+ const keyPath = path . resolve ( this . project . root , commandOptions . sslKey ) ;
54
+ if ( fs . existsSync ( keyPath ) ) {
55
+ sslKey = fs . readFileSync ( keyPath , 'utf-8' ) ;
56
+ }
57
+ const certPath = path . resolve ( this . project . root , commandOptions . sslCert ) ;
58
+ if ( fs . existsSync ( certPath ) ) {
59
+ sslCert = fs . readFileSync ( certPath , 'utf-8' ) ;
60
+ }
61
+ }
62
+
49
63
const webpackDevServerConfiguration : IWebpackDevServerConfigurationOptions = {
50
64
contentBase : path . resolve (
51
65
this . project . root ,
@@ -54,19 +68,25 @@ export default Task.extend({
54
68
historyApiFallback : true ,
55
69
stats : webpackDevServerOutputOptions ,
56
70
inline : true ,
71
+ https : commandOptions . ssl ,
57
72
proxy : proxyConfig
58
73
} ;
59
74
75
+ if ( sslKey != null && sslCert != null ) {
76
+ webpackDevServerConfiguration . key = sslKey ;
77
+ webpackDevServerConfiguration . cert = sslCert ;
78
+ }
79
+
60
80
ui . writeLine ( chalk . green ( oneLine `
61
81
**
62
82
NG Live Development Server is running on
63
- http://${ commandOptions . host } :${ commandOptions . port } .
83
+ http${ commandOptions . ssl ? 's' : '' } ://${ commandOptions . host } :${ commandOptions . port } .
64
84
**
65
85
` ) ) ;
66
86
67
87
const server = new WebpackDevServer ( webpackCompiler , webpackDevServerConfiguration ) ;
68
88
return new Promise ( ( resolve , reject ) => {
69
- server . listen ( commandOptions . port , `${ commandOptions . host } ` , function ( err : any , stats : any ) {
89
+ server . listen ( commandOptions . port , `${ commandOptions . host } ` , function ( err : any , stats : any ) {
70
90
if ( err ) {
71
91
console . error ( err . stack || err ) ;
72
92
if ( err . details ) { console . error ( err . details ) ; }
0 commit comments