Skip to content

Commit 815b49a

Browse files
committed
feat(serve): forward --ssl to Angular CLI
By using the Angular CLI's `--ssl` option, the webpack server will auto-generate an SSL certificate at runtime. Devs will need to confirm the self-signed certificate in their browsers in order to load the app using `ionic serve --ssl`. Known limitations: * DevApp does not yet support apps on HTTPS (#3748) * The iOS Web View does not support self-signed certificates yet references #3305
1 parent 302b68c commit 815b49a

File tree

4 files changed

+19
-49
lines changed

4 files changed

+19
-49
lines changed

packages/ionic/src/commands/serve.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ export class ServeCommand extends Command implements CommandPreRun {
6363
type: Boolean,
6464
aliases: ['l'],
6565
},
66-
{
67-
name: 'auth',
68-
summary: 'HTTP Basic Auth password to secure the server on your local network',
69-
type: String,
70-
groups: [OptionGroup.Hidden],
71-
},
7266
];
7367

7468
const exampleCommands = ['', '-c', '--local', '--lab'];

packages/ionic/src/definitions.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,6 @@ export interface IProjectConfig {
237237

238238
readonly integrations: ProjectIntegrations;
239239
readonly hooks?: Record<HookName, string | string[] | undefined>;
240-
241-
ssl?: {
242-
key?: string;
243-
cert?: string;
244-
};
245240
}
246241

247242
export interface IMultiProjectConfig {
@@ -550,7 +545,6 @@ export interface ServeOptions {
550545
// Command Options
551546
address: string;
552547
port: number;
553-
ssl: boolean;
554548
livereload: boolean;
555549
proxy: boolean;
556550
lab: boolean;
@@ -570,6 +564,7 @@ export interface ServeOptions {
570564
}
571565

572566
export interface AngularServeOptions extends ServeOptions {
567+
ssl?: boolean;
573568
configuration?: string;
574569
sourcemaps?: boolean;
575570
}
@@ -592,13 +587,8 @@ export interface Ionic1ServeOptions extends ServeOptions {
592587

593588
export interface LabServeDetails {
594589
projectType: ProjectType;
595-
protocol: string;
596590
address: string;
597591
port: number;
598-
ssl?: {
599-
key: string;
600-
cert: string;
601-
};
602592
}
603593

604594
export interface DevAppDetails {

packages/ionic/src/lib/project/angular/serve.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@ import { BIND_ALL_ADDRESS, LOCAL_ADDRESSES, SERVE_SCRIPT, ServeCLI, ServeRunner,
88

99
import { AngularProject } from './';
1010

11-
const NG_SERVE_OPTIONS = [
12-
{
13-
name: 'configuration',
14-
summary: 'Specify the configuration to use.',
15-
type: String,
16-
groups: [OptionGroup.Advanced],
17-
hint: chalk.dim('[ng]'),
18-
},
19-
];
20-
2111
export interface AngularServeRunnerDeps extends ServeRunnerDeps {
2212
readonly project: AngularProject;
2313
}
@@ -35,20 +25,32 @@ ${chalk.green('ionic serve')} uses the Angular CLI. Use ${chalk.green('ng serve
3525
3626
${chalk.cyan('[1]')}: ${chalk.bold('https://github.com/angular/angular-cli/wiki/serve')}`,
3727
options: [
28+
{
29+
name: 'ssl',
30+
summary: 'Use HTTPS for the dev server',
31+
type: Boolean,
32+
hint: chalk.dim('[ng]'),
33+
},
3834
{
3935
name: 'prod',
4036
summary: `Flag to use the ${chalk.green('production')} configuration`,
4137
type: Boolean,
4238
hint: chalk.dim('[ng]'),
4339
},
40+
{
41+
name: 'configuration',
42+
summary: 'Specify the configuration to use.',
43+
type: String,
44+
groups: [OptionGroup.Advanced],
45+
hint: chalk.dim('[ng]'),
46+
},
4447
{
4548
name: 'source-map',
4649
summary: 'Output sourcemaps',
4750
type: Boolean,
4851
groups: [OptionGroup.Advanced],
4952
hint: chalk.dim('[ng]'),
5053
},
51-
...NG_SERVE_OPTIONS,
5254
],
5355
exampleCommands: [
5456
'-- --proxy-config proxy.conf.json',
@@ -59,11 +61,13 @@ ${chalk.cyan('[1]')}: ${chalk.bold('https://github.com/angular/angular-cli/wiki/
5961
createOptionsFromCommandLine(inputs: CommandLineInputs, options: CommandLineOptions): AngularServeOptions {
6062
const baseOptions = super.createOptionsFromCommandLine(inputs, options);
6163
const prod = options['prod'] ? Boolean(options['prod']) : undefined;
64+
const ssl = options['ssl'] ? Boolean(options['ssl']) : undefined;
6265
const configuration = options['configuration'] ? String(options['configuration']) : (prod ? 'production' : undefined);
6366
const sourcemaps = typeof options['source-map'] === 'boolean' ? Boolean(options['source-map']) : undefined;
6467

6568
return {
6669
...baseOptions,
70+
ssl,
6771
configuration,
6872
sourcemaps,
6973
};
@@ -91,7 +95,7 @@ ${chalk.cyan('[1]')}: ${chalk.bold('https://github.com/angular/angular-cli/wiki/
9195

9296
return {
9397
custom: ng.resolvedProgram !== ng.program,
94-
protocol: 'http',
98+
protocol: options.ssl ? 'https' : 'http',
9599
localAddress: 'localhost',
96100
externalAddress: externalIP,
97101
externalNetworkInterfaces: availableInterfaces,
@@ -140,6 +144,7 @@ export class AngularServeCLI extends ServeCLI<AngularServeOptions> {
140144
host: options.address,
141145
port: String(options.port),
142146
'source-map': options.sourcemaps !== false ? options.sourcemaps : 'false',
147+
'ssl': options.ssl !== false ? options.ssl : 'false',
143148
};
144149

145150
let separatedArgs = options['--'];

packages/ionic/src/lib/serve.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ export abstract class ServeRunner<T extends ServeOptions> implements Runner<T, S
117117
platform: options['platform'] ? String(options['platform']) : undefined,
118118
port,
119119
proxy: typeof options['proxy'] === 'boolean' ? Boolean(options['proxy']) : true,
120-
ssl: false,
121120
project: options['project'] ? String(options['project']) : undefined,
122121
};
123122
}
@@ -182,7 +181,7 @@ export abstract class ServeRunner<T extends ServeOptions> implements Runner<T, S
182181

183182
const localAddress = `${details.protocol}://localhost:${details.port}`;
184183
const fmtExternalAddress = (address: string) => `${details.protocol}://${address}:${details.port}`;
185-
const labAddress = labDetails ? `${labDetails.protocol}://${labDetails.address}:${labDetails.port}` : undefined;
184+
const labAddress = labDetails ? `http://${labDetails.address}:${labDetails.port}` : undefined;
186185

187186
this.e.log.nl();
188187
this.e.log.info(
@@ -312,24 +311,10 @@ export abstract class ServeRunner<T extends ServeOptions> implements Runner<T, S
312311
async runLab(options: T, serveDetails: ServeDetails): Promise<LabServeDetails> {
313312
const labDetails: LabServeDetails = {
314313
projectType: this.e.project.type,
315-
protocol: options.ssl ? 'https' : 'http',
316314
address: options.labHost,
317315
port: await findClosestOpenPort(options.labPort),
318316
};
319317

320-
if (options.ssl) {
321-
const sslConfig = this.e.project.config.get('ssl');
322-
323-
if (sslConfig && sslConfig.key && sslConfig.cert) {
324-
labDetails.ssl = { key: sslConfig.key, cert: sslConfig.cert };
325-
} else {
326-
throw new FatalException(
327-
`Both ${chalk.green('ssl.key')} and ${chalk.green('ssl.cert')} config entries must be set.\n` +
328-
`See ${chalk.green('ionic serve --help')} for details on using your own SSL key and certificate for Ionic Lab and the dev server.`
329-
);
330-
}
331-
}
332-
333318
const lab = new IonicLabServeCLI(this.e);
334319
await lab.serve({ serveDetails, ...labDetails });
335320

@@ -654,10 +639,6 @@ class IonicLabServeCLI extends ServeCLI<IonicLabServeCLIOptions> {
654639
const nameArgs = appName ? ['--app-name', appName] : [];
655640
const versionArgs = pkg.version ? ['--app-version', pkg.version] : [];
656641

657-
if (labDetails.ssl) {
658-
labArgs.push('--ssl', '--ssl-key', labDetails.ssl.key, '--ssl-cert', labDetails.ssl.cert);
659-
}
660-
661642
return [...labArgs, ...nameArgs, ...versionArgs];
662643
}
663644
}

0 commit comments

Comments
 (0)