Skip to content

Commit

Permalink
feat(@angular/cli): allow setting ssl certificate in angular-cli.json (
Browse files Browse the repository at this point in the history
…#4730)

Currently users must use the --ssl, -ssl-cert, -ssl-key flags to run the
server using an ssl certificate. This update allows users to set
those options in default.serve so they can just run `ng serve` without any
flags.
  • Loading branch information
itslenny authored and hansl committed Feb 22, 2017
1 parent 4b32bb4 commit b498549
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/@angular/cli/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const Command = require('../ember-cli/lib/models/command');
const config = CliConfig.fromProject() || CliConfig.fromGlobal();
const defaultPort = process.env.PORT || config.get('defaults.serve.port');
const defaultHost = config.get('defaults.serve.host');
const defaultSsl = config.get('defaults.serve.ssl');
const defaultSslKey = config.get('defaults.serve.sslKey');
const defaultSslCert = config.get('defaults.serve.sslCert');

export interface ServeTaskOptions extends BuildOptions {
port?: number;
Expand All @@ -37,9 +40,9 @@ export const baseServeCommandOptions: any = overrideOptions(
description: `Listens only on ${defaultHost} by default`
},
{ name: 'proxy-config', type: 'Path', aliases: ['pc'] },
{ name: 'ssl', type: Boolean, default: false },
{ name: 'ssl-key', type: String, default: 'ssl/server.key' },
{ name: 'ssl-cert', type: String, default: 'ssl/server.crt' },
{ name: 'ssl', type: Boolean, default: defaultSsl },
{ name: 'ssl-key', type: String, default: defaultSslKey },
{ name: 'ssl-cert', type: String, default: defaultSslCert },
{
name: 'open',
type: Boolean,
Expand Down
18 changes: 18 additions & 0 deletions packages/@angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,24 @@
"description": "The host the application will be served on",
"type": "string",
"default": "localhost"

},
"ssl": {
"description": "Enables ssl for the application",
"type": "boolean",
"default": false

},
"sslKey": {
"description": "The ssl key used by the server",
"type": "string",
"default": "ssl/server.key"

},
"sslCert": {
"description": "The ssl certificate used by the server",
"type": "string",
"default": "ssl/server.crt"
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions tests/e2e/tests/misc/ssl-default-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { request } from '../../utils/http';
import { killAllProcesses } from '../../utils/process';
import { ngServe } from '../../utils/project';
import { updateJsonFile } from '../../utils/project';

export default function() {
return Promise.resolve()
.then(() => updateJsonFile('.angular-cli.json', configJson => {
const app = configJson.defaults;
app.serve = { ssl: true };
}))
.then(() => ngServe())
.then(() => request('https://localhost:4200/'))
.then(body => {
if (!body.match(/<app-root>Loading...<\/app-root>/)) {
throw new Error('Response does not match expected value.');
}
})
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; });
}
26 changes: 26 additions & 0 deletions tests/e2e/tests/misc/ssl-with-cert-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { request } from '../../utils/http';
import { assetDir } from '../../utils/assets';
import { killAllProcesses } from '../../utils/process';
import { ngServe } from '../../utils/project';
import { updateJsonFile } from '../../utils/project';

export default function() {
return Promise.resolve()
.then(() => updateJsonFile('.angular-cli.json', configJson => {
const app = configJson.defaults;
app.serve = {
ssl: true,
sslKey: assetDir('ssl/server.key'),
sslCert: assetDir('ssl/server.crt')
};
}))
.then(() => ngServe())
.then(() => request('https://localhost:4200/'))
.then(body => {
if (!body.match(/<app-root>Loading...<\/app-root>/)) {
throw new Error('Response does not match expected value.');
}
})
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; });

}

0 comments on commit b498549

Please sign in to comment.