From 55672d1fe9755863c7f9e7155889ea6a224a261d Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sun, 25 Dec 2016 19:33:16 -0500 Subject: [PATCH] Update multi_server.dart --- bin/multi_server.dart | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/bin/multi_server.dart b/bin/multi_server.dart index 3960384..e44e0bf 100644 --- a/bin/multi_server.dart +++ b/bin/multi_server.dart @@ -3,7 +3,18 @@ import 'dart:io'; import 'package:angel_multiserver/angel_multiserver.dart'; final Uri cluster = Platform.script.resolve('cluster.dart'); -final errorPage = GZIP.encode(UTF8.encode(''' +final error502 = GZIP.encode(UTF8.encode(''' + + + + 502 Bad Gateway + + +

502 Bad Gateway

+ + + ''')); +final error503 = GZIP.encode(UTF8.encode(''' @@ -25,13 +36,25 @@ main() async { // Auto-spawn a new instance on crash 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 { socket ..writeln('HTTP/1.1 503 Service Unavailable') ..writeln(HttpDate.format(new DateTime.now())) ..writeln('Content-Encoding: gzip') ..writeln() - ..add(errorPage) + ..add(error503) ..writeln(); await socket.close(); }); @@ -39,4 +62,4 @@ main() async { var server = await loadBalancer.startServer(); print( 'Load balancer listening at http://${server.address.address}:${server.port}'); -} \ No newline at end of file +}