protevus/bin/multi_server.dart

37 lines
1.1 KiB
Dart
Raw Normal View History

2017-01-14 23:52:25 +00:00
#!/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
2017-01-14 23:52:57 +00:00
/// reason to use them together.
2017-01-14 23:52:25 +00:00
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
2017-03-23 12:50:03 +00:00
await app.configure(cacheResponses(filters: [new RegExp(r'images/\.*')]));
2017-01-14 23:52:25 +00:00
// 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;
2017-01-15 00:25:33 +00:00
var port = 3000;
2017-01-14 23:52:25 +00:00
var server = await app.startServer(host, port);
print('Listening at http://${server.address.address}:${server.port}');
}