diff --git a/packages/@angular/cli/commands/serve.ts b/packages/@angular/cli/commands/serve.ts index e9ed7c107943..41a8216af00f 100644 --- a/packages/@angular/cli/commands/serve.ts +++ b/packages/@angular/cli/commands/serve.ts @@ -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; @@ -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, diff --git a/packages/@angular/cli/lib/config/schema.json b/packages/@angular/cli/lib/config/schema.json index ad62cf40243d..647a77768be6 100644 --- a/packages/@angular/cli/lib/config/schema.json +++ b/packages/@angular/cli/lib/config/schema.json @@ -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" } } } diff --git a/tests/e2e/tests/misc/ssl-default-config.ts b/tests/e2e/tests/misc/ssl-default-config.ts new file mode 100644 index 000000000000..94d134879999 --- /dev/null +++ b/tests/e2e/tests/misc/ssl-default-config.ts @@ -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(/Loading...<\/app-root>/)) { + throw new Error('Response does not match expected value.'); + } + }) + .then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; }); +} diff --git a/tests/e2e/tests/misc/ssl-with-cert-config.ts b/tests/e2e/tests/misc/ssl-with-cert-config.ts new file mode 100644 index 000000000000..afb2e132c192 --- /dev/null +++ b/tests/e2e/tests/misc/ssl-with-cert-config.ts @@ -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(/Loading...<\/app-root>/)) { + throw new Error('Response does not match expected value.'); + } + }) + .then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; }); + +}