lib/invoker/power/balancer.rb in invoker-1.0.2 vs lib/invoker/power/balancer.rb in invoker-1.0.3

- old
+ new

@@ -71,11 +71,12 @@ if config connection.server(session, host: '0.0.0.0', port: config.port) connection.relay_to_servers(@buffer.join) @buffer = [] else - connection.unbind + return_error_page(404) + connection.close_connection_after_writing end end def upstream_data(data) unless session @@ -93,15 +94,21 @@ http_parser.reset connection.close_connection_after_writing end def backend_data(backend, data) + @backend_data = true data end def frontend_disconnect(backend, name) http_parser.reset() + unless @backend_data + Invoker::Logger.puts("\nApplication not running. Returning error page.".color(:red)) + return_error_page(503) + end + @backend_data = false connection.close_connection_after_writing() if backend == session end private def select_backend_config(host) @@ -110,9 +117,17 @@ if selected_app = matching_string[1] Invoker::CONFIG.process(selected_app) else nil end + end + + def return_error_page(status) + http_response = Invoker::Power::HttpResponse.new() + http_response.status = status + http_response['Content-Type'] = "text/html; charset=utf-8" + http_response.use_file_as_body(File.join(File.dirname(__FILE__), "templates/#{status}.html")) + connection.send_data(http_response.http_string) end end end end