Skip to content

Commit 3cf60a8

Browse files
author
Jonathan Jayet
committed
Fixed the ssl command not working anymore
1 parent 2a03a33 commit 3cf60a8

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

packages/angular-cli/custom-typings.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ interface IWebpackDevServerConfigurationOptions {
1717
headers?: { [key: string]: string };
1818
stats?: { [key: string]: boolean };
1919
inline: boolean;
20+
https?:boolean;
21+
key?: string;
22+
cert?: string;
2023
}
2124

2225
interface WebpackProgressPluginOutputOptions {

packages/angular-cli/tasks/serve-webpack.ts

+23-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { CliConfig } from '../models/config';
1313
import { oneLine } from 'common-tags';
1414

1515
export default Task.extend({
16-
run: function(commandOptions: ServeTaskOptions) {
16+
run: function (commandOptions: ServeTaskOptions) {
1717
const ui = this.ui;
1818

1919
let webpackCompiler: any;
@@ -46,6 +46,20 @@ export default Task.extend({
4646
}
4747
}
4848

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+
4963
const webpackDevServerConfiguration: IWebpackDevServerConfigurationOptions = {
5064
contentBase: path.resolve(
5165
this.project.root,
@@ -54,19 +68,25 @@ export default Task.extend({
5468
historyApiFallback: true,
5569
stats: webpackDevServerOutputOptions,
5670
inline: true,
71+
https: commandOptions.ssl,
5772
proxy: proxyConfig
5873
};
5974

75+
if (sslKey != null && sslCert != null) {
76+
webpackDevServerConfiguration.key = sslKey;
77+
webpackDevServerConfiguration.cert = sslCert;
78+
}
79+
6080
ui.writeLine(chalk.green(oneLine`
6181
**
6282
NG Live Development Server is running on
63-
http://${commandOptions.host}:${commandOptions.port}.
83+
http${commandOptions.ssl ? 's' : ''}://${commandOptions.host}:${commandOptions.port}.
6484
**
6585
`));
6686

6787
const server = new WebpackDevServer(webpackCompiler, webpackDevServerConfiguration);
6888
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) {
7090
if (err) {
7191
console.error(err.stack || err);
7292
if (err.details) { console.error(err.details); }

0 commit comments

Comments
 (0)