Updated diagnostics, multiserver

This commit is contained in:
thosakwe 2017-01-14 18:52:25 -05:00
parent c68f2d981a
commit da993e3779
4 changed files with 50 additions and 7 deletions

View file

@ -20,9 +20,13 @@ startServer(args, {bool clustered: false, SendPort sendPort}) {
port = 0;
}
var server =
await new DiagnosticsServer(app, logFile).startServer(host, port);
sendPort?.send([server.address.address, server.port]);
await app.configure(logRequests(logFile));
var server = await app.startServer(host, port);
if (sendPort == null) {
print('Listening at http://${server.address.address}:${server.port}');
} else
sendPort?.send([server.address.address, server.port]);
};
}

36
bin/multi_server.dart Normal file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env dart
/// This is intended to replace Nginx in your web stack.
/// Either use this or another reverse proxy, but there is no real
/// response to use them together.
library angel.multiserver;
import 'dart:io';
import 'package:angel_compress/angel_compress.dart';
import 'package:angel_multiserver/angel_multiserver.dart';
final Uri cluster = Platform.script.resolve('cluster.dart');
main() async {
var app = new LoadBalancer();
// Or, for SSL:
// var app = new LoadBalancer.secure('<server-chain>', '<server-key>');
// Response compression!
app.responseFinalizers.add(gzip());
// Cache static assets - just to lower response time
await app.configure(cacheResponses(filters: [new RegExp('images/\.*')]));
// Start up 5 instances of our main application
await app.spawnIsolates(cluster, count: 5);
app.onCrash.listen((_) async {
// Boot up a new instance on crash
await app.spawnIsolates(cluster);
});
var host = InternetAddress.ANY_IP_V4;
var port = 80;
var server = await app.startServer(host, port);
print('Listening at http://${server.address.address}:${server.port}');
}

View file

@ -46,7 +46,10 @@ configureAfter(Angel app) async {
await app.configure(errors);
// Compress via GZIP
app.responseFinalizers.add(gzip());
// Ideally you'll run this on a `multiserver` instance, but if not,
// feel free to knock yourself out!
//
// app.responseFinalizers.add(gzip());
}
configureServer(Angel app) async {

View file

@ -33,7 +33,7 @@ class UserService extends Service {
index([Map params]) {
if (params != null && params.containsKey('provider')) {
// Nobody needs to see the entire user list except for the server.
throw new AngelHttpException.Forbidden();
throw new AngelHttpException.forbidden();
}
return _inner.index(params);
@ -43,7 +43,7 @@ class UserService extends Service {
create(data, [Map params]) {
if (params != null && params.containsKey('provider')) {
// Deny creating users to the public - this should be done by the server only.
throw new AngelHttpException.Forbidden();
throw new AngelHttpException.forbidden();
}
try {
@ -52,7 +52,7 @@ class UserService extends Service {
Validate.isEmail(data['email']);
data['password'] = hashPassword(data['password']);
} catch (e) {
throw new AngelHttpException.BadRequest(
throw new AngelHttpException.badRequest(
message: 'User must have a username, e-mail address and password.');
}