diff --git a/packages/production/lib/src/options.dart b/packages/production/lib/src/options.dart index 8d3fb40a..8a7e0eab 100644 --- a/packages/production/lib/src/options.dart +++ b/packages/production/lib/src/options.dart @@ -36,7 +36,7 @@ class RunnerOptions { certificatePassword, keyPassword; final int concurrency, port; - final bool? useZone, respawn, quiet, ssl, http2; + final bool useZone, respawn, quiet, ssl, http2; RunnerOptions( {this.hostname = '127.0.0.1', @@ -57,17 +57,17 @@ class RunnerOptions { hostname: argResults['address'] as String?, port: int.parse(argResults['port'] as String), concurrency: int.parse(argResults['concurrency'] as String), - useZone: argResults['use-zone'] as bool?, - respawn: argResults['respawn'] as bool?, - quiet: argResults['quiet'] as bool?, + useZone: argResults['use-zone'] as bool? ?? false, + respawn: argResults['respawn'] as bool? ?? true, + quiet: argResults['quiet'] as bool? ?? false, certificateFile: argResults.wasParsed('certificate-file') ? argResults['certificate-file'] as String? : null, keyFile: argResults.wasParsed('key-file') ? argResults['key-file'] as String? : null, - ssl: argResults['ssl'] as bool?, - http2: argResults['http2'] as bool?, + ssl: argResults['ssl'] as bool? ?? false, + http2: argResults['http2'] as bool? ?? false, certificatePassword: argResults.wasParsed('certificate-password') ? argResults['certificate-password'] as String? : null, diff --git a/packages/production/lib/src/runner.dart b/packages/production/lib/src/runner.dart index be5038df..2cf78671 100644 --- a/packages/production/lib/src/runner.dart +++ b/packages/production/lib/src/runner.dart @@ -55,7 +55,7 @@ _ ___ | /| / / /_/ / _ /___ _ /___ '''; static void handleLogRecord(LogRecord? record, RunnerOptions options) { - if (options.quiet!) return; + if (options.quiet) return; var code = chooseLogColor(record!.level); if (record.error == null) print(code.wrap(record.toString())); @@ -137,7 +137,7 @@ _ ___ | /| / / /_/ / _ /___ _ /___ }); onExit.listen((_) { - if (options.respawn!) { + if (options.respawn) { handleLogRecord( LogRecord( Level.WARNING, @@ -164,7 +164,7 @@ _ ___ | /| / / /_/ / _ /___ _ /___ var argResults = RunnerOptions.argParser.parse(args); var options = RunnerOptions.fromArgResults(argResults); - if (options.ssl! || options.http2!) { + if (options.ssl || options.http2) { if (options.certificateFile == null) { throw ArgParserException('Missing --certificate-file option.'); } else if (options.keyFile == null) { @@ -243,28 +243,33 @@ _ ___ | /| / / /_/ / _ /___ _ /___ late SecurityContext securityContext; Uri serverUrl; - if (args.options.ssl! || args.options.http2!) { + if (args.options.ssl || args.options.http2) { securityContext = SecurityContext(); - securityContext.useCertificateChain(args.options.certificateFile!, - password: args.options.certificatePassword); - securityContext.usePrivateKey(args.options.keyFile!, - password: args.options.keyPassword); + if (args.options.certificateFile != null) { + securityContext.useCertificateChain(args.options.certificateFile!, + password: args.options.certificatePassword); + } + + if (args.options.keyFile != null) { + securityContext.usePrivateKey(args.options.keyFile!, + password: args.options.keyPassword); + } } - if (args.options.ssl!) { + if (args.options.ssl) { http = AngelHttp.custom(app, startSharedSecure(securityContext), - useZone: args.options.useZone!); + useZone: args.options.useZone); } else { http = - AngelHttp.custom(app, startShared, useZone: args.options.useZone!); + AngelHttp.custom(app, startShared, useZone: args.options.useZone); } Driver driver; - if (args.options.http2!) { + if (args.options.http2) { securityContext.setAlpnProtocols(['h2'], true); var http2 = AngelHttp2.custom(app, securityContext, startSharedHttp2, - useZone: args.options.useZone!); + useZone: args.options.useZone); http2.onHttp1.listen(http.handleRequest); driver = http2; } else { @@ -273,7 +278,7 @@ _ ___ | /| / / /_/ / _ /___ _ /___ await driver.startServer(args.options.hostname, args.options.port); serverUrl = driver.uri; - if (args.options.ssl! || args.options.http2!) { + if (args.options.ssl || args.options.http2) { serverUrl = serverUrl.replace(scheme: 'https'); } print('Instance #${argsWithId.id} listening at $serverUrl');