Update multi_server.dart
This commit is contained in:
parent
b7f56abf93
commit
55672d1fe9
1 changed files with 26 additions and 3 deletions
|
@ -3,7 +3,18 @@ import 'dart:io';
|
||||||
import 'package:angel_multiserver/angel_multiserver.dart';
|
import 'package:angel_multiserver/angel_multiserver.dart';
|
||||||
|
|
||||||
final Uri cluster = Platform.script.resolve('cluster.dart');
|
final Uri cluster = Platform.script.resolve('cluster.dart');
|
||||||
final errorPage = GZIP.encode(UTF8.encode('''
|
final error502 = GZIP.encode(UTF8.encode('''
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>502 Bad Gateway</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>502 Bad Gateway</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
'''));
|
||||||
|
final error503 = GZIP.encode(UTF8.encode('''
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
@ -25,13 +36,25 @@ main() async {
|
||||||
// Auto-spawn a new instance on crash
|
// Auto-spawn a new instance on crash
|
||||||
loadBalancer.spawnIsolates(cluster);
|
loadBalancer.spawnIsolates(cluster);
|
||||||
})
|
})
|
||||||
|
..onErrored.listen((socket) async {
|
||||||
|
try {
|
||||||
|
socket
|
||||||
|
..writeln('HTTP/1.1 502 Bad Gateway')
|
||||||
|
..writeln(HttpDate.format(new DateTime.now()))
|
||||||
|
..writeln('Content-Encoding: gzip')
|
||||||
|
..writeln()
|
||||||
|
..add(error502)
|
||||||
|
..writeln();
|
||||||
|
await socket.close();
|
||||||
|
} catch(_) {}
|
||||||
|
})
|
||||||
..onUnavailable.listen((socket) async {
|
..onUnavailable.listen((socket) async {
|
||||||
socket
|
socket
|
||||||
..writeln('HTTP/1.1 503 Service Unavailable')
|
..writeln('HTTP/1.1 503 Service Unavailable')
|
||||||
..writeln(HttpDate.format(new DateTime.now()))
|
..writeln(HttpDate.format(new DateTime.now()))
|
||||||
..writeln('Content-Encoding: gzip')
|
..writeln('Content-Encoding: gzip')
|
||||||
..writeln()
|
..writeln()
|
||||||
..add(errorPage)
|
..add(error503)
|
||||||
..writeln();
|
..writeln();
|
||||||
await socket.close();
|
await socket.close();
|
||||||
});
|
});
|
||||||
|
@ -39,4 +62,4 @@ main() async {
|
||||||
var server = await loadBalancer.startServer();
|
var server = await loadBalancer.startServer();
|
||||||
print(
|
print(
|
||||||
'Load balancer listening at http://${server.address.address}:${server.port}');
|
'Load balancer listening at http://${server.address.address}:${server.port}');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue