Updated production

This commit is contained in:
thomashii 2021-07-18 13:49:37 +08:00
parent 9da4eeeb46
commit 82a8c9caed
2 changed files with 25 additions and 20 deletions

View file

@ -36,7 +36,7 @@ class RunnerOptions {
certificatePassword, certificatePassword,
keyPassword; keyPassword;
final int concurrency, port; final int concurrency, port;
final bool? useZone, respawn, quiet, ssl, http2; final bool useZone, respawn, quiet, ssl, http2;
RunnerOptions( RunnerOptions(
{this.hostname = '127.0.0.1', {this.hostname = '127.0.0.1',
@ -57,17 +57,17 @@ class RunnerOptions {
hostname: argResults['address'] as String?, hostname: argResults['address'] as String?,
port: int.parse(argResults['port'] as String), port: int.parse(argResults['port'] as String),
concurrency: int.parse(argResults['concurrency'] as String), concurrency: int.parse(argResults['concurrency'] as String),
useZone: argResults['use-zone'] as bool?, useZone: argResults['use-zone'] as bool? ?? false,
respawn: argResults['respawn'] as bool?, respawn: argResults['respawn'] as bool? ?? true,
quiet: argResults['quiet'] as bool?, quiet: argResults['quiet'] as bool? ?? false,
certificateFile: argResults.wasParsed('certificate-file') certificateFile: argResults.wasParsed('certificate-file')
? argResults['certificate-file'] as String? ? argResults['certificate-file'] as String?
: null, : null,
keyFile: argResults.wasParsed('key-file') keyFile: argResults.wasParsed('key-file')
? argResults['key-file'] as String? ? argResults['key-file'] as String?
: null, : null,
ssl: argResults['ssl'] as bool?, ssl: argResults['ssl'] as bool? ?? false,
http2: argResults['http2'] as bool?, http2: argResults['http2'] as bool? ?? false,
certificatePassword: argResults.wasParsed('certificate-password') certificatePassword: argResults.wasParsed('certificate-password')
? argResults['certificate-password'] as String? ? argResults['certificate-password'] as String?
: null, : null,

View file

@ -55,7 +55,7 @@ _ ___ | /| / / /_/ / _ /___ _ /___
'''; ''';
static void handleLogRecord(LogRecord? record, RunnerOptions options) { static void handleLogRecord(LogRecord? record, RunnerOptions options) {
if (options.quiet!) return; if (options.quiet) return;
var code = chooseLogColor(record!.level); var code = chooseLogColor(record!.level);
if (record.error == null) print(code.wrap(record.toString())); if (record.error == null) print(code.wrap(record.toString()));
@ -137,7 +137,7 @@ _ ___ | /| / / /_/ / _ /___ _ /___
}); });
onExit.listen((_) { onExit.listen((_) {
if (options.respawn!) { if (options.respawn) {
handleLogRecord( handleLogRecord(
LogRecord( LogRecord(
Level.WARNING, Level.WARNING,
@ -164,7 +164,7 @@ _ ___ | /| / / /_/ / _ /___ _ /___
var argResults = RunnerOptions.argParser.parse(args); var argResults = RunnerOptions.argParser.parse(args);
var options = RunnerOptions.fromArgResults(argResults); var options = RunnerOptions.fromArgResults(argResults);
if (options.ssl! || options.http2!) { if (options.ssl || options.http2) {
if (options.certificateFile == null) { if (options.certificateFile == null) {
throw ArgParserException('Missing --certificate-file option.'); throw ArgParserException('Missing --certificate-file option.');
} else if (options.keyFile == null) { } else if (options.keyFile == null) {
@ -243,28 +243,33 @@ _ ___ | /| / / /_/ / _ /___ _ /___
late SecurityContext securityContext; late SecurityContext securityContext;
Uri serverUrl; Uri serverUrl;
if (args.options.ssl! || args.options.http2!) { if (args.options.ssl || args.options.http2) {
securityContext = SecurityContext(); securityContext = SecurityContext();
securityContext.useCertificateChain(args.options.certificateFile!, if (args.options.certificateFile != null) {
password: args.options.certificatePassword); securityContext.useCertificateChain(args.options.certificateFile!,
securityContext.usePrivateKey(args.options.keyFile!, password: args.options.certificatePassword);
password: args.options.keyPassword); }
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), http = AngelHttp.custom(app, startSharedSecure(securityContext),
useZone: args.options.useZone!); useZone: args.options.useZone);
} else { } else {
http = http =
AngelHttp.custom(app, startShared, useZone: args.options.useZone!); AngelHttp.custom(app, startShared, useZone: args.options.useZone);
} }
Driver driver; Driver driver;
if (args.options.http2!) { if (args.options.http2) {
securityContext.setAlpnProtocols(['h2'], true); securityContext.setAlpnProtocols(['h2'], true);
var http2 = AngelHttp2.custom(app, securityContext, startSharedHttp2, var http2 = AngelHttp2.custom(app, securityContext, startSharedHttp2,
useZone: args.options.useZone!); useZone: args.options.useZone);
http2.onHttp1.listen(http.handleRequest); http2.onHttp1.listen(http.handleRequest);
driver = http2; driver = http2;
} else { } else {
@ -273,7 +278,7 @@ _ ___ | /| / / /_/ / _ /___ _ /___
await driver.startServer(args.options.hostname, args.options.port); await driver.startServer(args.options.hostname, args.options.port);
serverUrl = driver.uri; serverUrl = driver.uri;
if (args.options.ssl! || args.options.http2!) { if (args.options.ssl || args.options.http2) {
serverUrl = serverUrl.replace(scheme: 'https'); serverUrl = serverUrl.replace(scheme: 'https');
} }
print('Instance #${argsWithId.id} listening at $serverUrl'); print('Instance #${argsWithId.id} listening at $serverUrl');