diff --git a/bin/cluster.dart b/bin/cluster.dart new file mode 100644 index 0000000..8403f8c --- /dev/null +++ b/bin/cluster.dart @@ -0,0 +1,11 @@ +/// This should be used with `multiserver` as an entry +/// point for `spawnIsolates`. +library angel.cluster; + +import 'dart:async'; +import 'common.dart'; + +main() async { + runZoned(startServer(clustered: true), onError: onError); +} + diff --git a/bin/common.dart b/bin/common.dart new file mode 100644 index 0000000..6c59228 --- /dev/null +++ b/bin/common.dart @@ -0,0 +1,34 @@ +import 'dart:io'; +import 'dart:isolate'; +import 'package:angel/angel.dart'; +import 'package:angel_diagnostics/angel_diagnostics.dart'; +import 'package:intl/intl.dart'; + +startServer({bool clustered: false}) { + return (args, [SendPort sendPort]) async { + var app = await createServer(); + var dateFormat = new DateFormat("y-MM-dd"); + var logFile = new File("logs/${dateFormat.format(new DateTime.now())}.txt"); + InternetAddress host; + int port; + + if (!clustered) { + host = new InternetAddress(app.properties['host']); + port = app.properties['port']; + } else { + host = InternetAddress.LOOPBACK_IP_V4; + port = 0; + } + + var server = + await new DiagnosticsServer(app, logFile).startServer(host, port); + sendPort?.send([server.address.address, server.port]); + }; +} + +onError(error, [StackTrace stackTrace]) { + stderr.writeln("Unhandled error occurred: $error"); + if (stackTrace != null) { + stderr.writeln(stackTrace); + } +} diff --git a/bin/server.dart b/bin/server.dart index 48d5fdb..fd46b52 100755 --- a/bin/server.dart +++ b/bin/server.dart @@ -1,28 +1,7 @@ #!/usr/bin/env dart - import 'dart:async'; -import 'dart:io'; -import 'package:angel/angel.dart'; -import 'package:angel_diagnostics/angel_diagnostics.dart'; -import 'package:intl/intl.dart'; +import 'common.dart'; main() async { - runZoned(startServer, onError: onError); -} - -startServer() async { - var app = await createServer(); - var dateFormat = new DateFormat("y-MM-dd"); - var logFile = new File("logs/${dateFormat.format(new DateTime.now())}.txt"); - var host = new InternetAddress(app.properties['host']); - var port = app.properties['port']; - - await new DiagnosticsServer(app, logFile).startServer(host, port); -} - -onError(error, [StackTrace stackTrace]) { - stderr.writeln("Unhandled error occurred: $error"); - if (stackTrace != null) { - stderr.writeln(stackTrace); - } + runZoned(startServer(), onError: onError); } diff --git a/lib/src/routes/controllers/auth.dart b/lib/src/routes/controllers/auth.dart index 3fdca86..292590b 100644 --- a/lib/src/routes/controllers/auth.dart +++ b/lib/src/routes/controllers/auth.dart @@ -28,9 +28,9 @@ class AuthController extends Controller { // Wire up local authentication, connected to our User service auth = new AngelAuth(jwtKey: app.jwt_secret) ..serializer = serializer - ..deserializer = deserializer; - ..strategies - .add(new LocalAuthStrategy(verifier(app.container.make(UserService)))); + ..deserializer = deserializer + ..strategies.add( + new LocalAuthStrategy(verifier(app.container.make(UserService)))); await super.call(app); await app.configure(auth);