Updated diagnostics, multiserver
This commit is contained in:
parent
c68f2d981a
commit
da993e3779
4 changed files with 50 additions and 7 deletions
|
@ -20,8 +20,12 @@ startServer(args, {bool clustered: false, SendPort sendPort}) {
|
||||||
port = 0;
|
port = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var server =
|
await app.configure(logRequests(logFile));
|
||||||
await new DiagnosticsServer(app, logFile).startServer(host, port);
|
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]);
|
sendPort?.send([server.address.address, server.port]);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
36
bin/multi_server.dart
Normal file
36
bin/multi_server.dart
Normal 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}');
|
||||||
|
}
|
|
@ -46,7 +46,10 @@ configureAfter(Angel app) async {
|
||||||
await app.configure(errors);
|
await app.configure(errors);
|
||||||
|
|
||||||
// Compress via GZIP
|
// 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 {
|
configureServer(Angel app) async {
|
||||||
|
|
|
@ -33,7 +33,7 @@ class UserService extends Service {
|
||||||
index([Map params]) {
|
index([Map params]) {
|
||||||
if (params != null && params.containsKey('provider')) {
|
if (params != null && params.containsKey('provider')) {
|
||||||
// Nobody needs to see the entire user list except for the server.
|
// Nobody needs to see the entire user list except for the server.
|
||||||
throw new AngelHttpException.Forbidden();
|
throw new AngelHttpException.forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
return _inner.index(params);
|
return _inner.index(params);
|
||||||
|
@ -43,7 +43,7 @@ class UserService extends Service {
|
||||||
create(data, [Map params]) {
|
create(data, [Map params]) {
|
||||||
if (params != null && params.containsKey('provider')) {
|
if (params != null && params.containsKey('provider')) {
|
||||||
// Deny creating users to the public - this should be done by the server only.
|
// Deny creating users to the public - this should be done by the server only.
|
||||||
throw new AngelHttpException.Forbidden();
|
throw new AngelHttpException.forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -52,7 +52,7 @@ class UserService extends Service {
|
||||||
Validate.isEmail(data['email']);
|
Validate.isEmail(data['email']);
|
||||||
data['password'] = hashPassword(data['password']);
|
data['password'] = hashPassword(data['password']);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new AngelHttpException.BadRequest(
|
throw new AngelHttpException.badRequest(
|
||||||
message: 'User must have a username, e-mail address and password.');
|
message: 'User must have a username, e-mail address and password.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue