Class: Slimer::WebApplication
- Inherits:
-
Object
- Object
- Slimer::WebApplication
- Extended by:
- WebRouter
- Defined in:
- lib/slimer/web/application.rb
Overview
Defines routes and responses for the Slimer web app.
Constant Summary collapse
- CONTENT_LENGTH =
"Content-Length"- REDIS_KEYS =
%w[redis_version uptime_in_days connected_clients used_memory_human used_memory_peak_human].freeze
- CSP_HEADER =
[ "default-src 'self' https: http:", "child-src 'self'", "connect-src 'self' https: http: wss: ws:", "font-src 'self' https: http:", "frame-src 'self'", "img-src 'self' https: http: data:", "manifest-src 'self'", "media-src 'self'", "object-src 'none'", "script-src 'self' https: http: 'unsafe-inline'", "style-src 'self' https: http: 'unsafe-inline'", "worker-src 'self'", "base-uri 'self'" ].join("; ").freeze
Constants included from WebRouter
Slimer::WebRouter::DELETE, Slimer::WebRouter::GET, Slimer::WebRouter::HEAD, Slimer::WebRouter::PATCH, Slimer::WebRouter::PATH_INFO, Slimer::WebRouter::POST, Slimer::WebRouter::PUT, Slimer::WebRouter::REQUEST_METHOD, Slimer::WebRouter::ROUTE_PARAMS
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(klass) ⇒ WebApplication
constructor
A new instance of WebApplication.
- #resolve_response(resp) ⇒ Object
- #root_path ⇒ Object
- #settings ⇒ Object
Methods included from WebRouter
delete, get, match, patch, post, put, route
Constructor Details
#initialize(klass) ⇒ WebApplication
Returns a new instance of WebApplication.
26 27 28 |
# File 'lib/slimer/web/application.rb', line 26 def initialize(klass) @klass = klass end |
Class Method Details
Instance Method Details
#call(env) ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/slimer/web/application.rb', line 86 def call(env) action = self.class.match(env) return [404, { "Content-Type" => "text/plain", "X-Cascade" => "pass" }, ["Not Found"]] unless action resp = catch(:halt) do action.instance_exec env, &action.block end resolve_response(resp) end |
#resolve_response(resp) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/slimer/web/application.rb', line 97 def resolve_response(resp) return resp if resp.is_a?(Array) # rendered content goes here headers = { "Content-Type" => "text/html", "Cache-Control" => "no-cache", "Content-Language" => "en", "Content-Security-Policy" => CSP_HEADER } # we'll let Rack calculate Content-Length for us. [200, headers, [resp]] end |
#root_path ⇒ Object
38 39 40 |
# File 'lib/slimer/web/application.rb', line 38 def root_path "#{env["SCRIPT_NAME"]}/" end |
#settings ⇒ Object
30 31 32 |
# File 'lib/slimer/web/application.rb', line 30 def settings @klass.settings end |