Class: Statusz::Server
- Inherits:
-
Object
- Object
- Statusz::Server
- Defined in:
- lib/statusz.rb
Overview
A Rack server that can serve statusz.
Instance Method Summary collapse
-
#call(env) ⇒ Object
The usual Rack app call method.
-
#initialize(filename = "./statusz.json", extra_fields = {}) ⇒ Server
constructor
Set up the Statusz::Server Rack app.
Constructor Details
#initialize(filename = "./statusz.json", extra_fields = {}) ⇒ Server
Set up the Statusz::Server Rack app.
116 117 118 119 |
# File 'lib/statusz.rb', line 116 def initialize(filename = "./statusz.json", extra_fields = {}) @filename = filename @extra_fields = extra_fields end |
Instance Method Details
#call(env) ⇒ Object
The usual Rack app call method.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/statusz.rb', line 122 def call(env) headers = {} path = Rack::Request.new(env).path if path =~ /\.json$/ headers["Content-Type"] = "application/json" format = :json elsif path =~ /\.txt$/ headers["Content-Type"] = "text/plain" format = :text else headers["Content-Type"] = "text/html" format = :html end begin body = Statusz.render_from_json(@filename, format, @extra_fields) rescue StandardError => error return [500, { "Content-Type" => "text/plain" }, ["Error with statusz:\n#{error.}"]] end [200, headers, [body]] end |