Scalable?
This commit is contained in:
parent
b55c687641
commit
02d378dedf
4 changed files with 50 additions and 26 deletions
11
bin/cluster.dart
Normal file
11
bin/cluster.dart
Normal file
|
@ -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);
|
||||
}
|
||||
|
34
bin/common.dart
Normal file
34
bin/common.dart
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue