Class: UniversalRenderer::Configuration
- Inherits:
-
Object
- Object
- UniversalRenderer::Configuration
- Defined in:
- lib/universal_renderer/configuration.rb
Overview
Configuration for UniversalRenderer.
Plain Ruby defaults only. Binding these to ENV is the host application's job, done in the generated initializer.
Defined Under Namespace
Classes: Http
Instance Attribute Summary collapse
-
#auto_include ⇒ Object
Whether the Rails engine includes Renderable into every ActionController::Base descendant.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#on_error ⇒ Object
Optional callable invoked as
call(error, context)when a configured render fails, wherecontextcarries at least:urland:outcome. -
#render_path ⇒ Object
Path the blocking renderer is mounted at.
-
#sanitize ⇒ Object
Whether
ssr_head/ssr_bodyrun the renderer's HTML through Loofah. -
#scrubber ⇒ Object
Scrubber instance used when
sanitizeis true. -
#stream_path ⇒ Object
Path the streaming renderer is mounted at on the SSR service.
-
#timeout ⇒ Object
Open and read timeout, in seconds, for every request to the SSR service.
-
#url ⇒ Object
Origin of the SSR service, e.g.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/universal_renderer/configuration.rb', line 69 def initialize @url = nil @timeout = 3 @render_path = nil @stream_path = "/stream" @sanitize = true @scrubber = nil @auto_include = true @on_error = nil @http = Http.new end |
Instance Attribute Details
#auto_include ⇒ Object
Whether the Rails engine includes Renderable into every ActionController::Base descendant. Turn it off and include the concern only in the controllers that render server-side.
57 58 59 |
# File 'lib/universal_renderer/configuration.rb', line 57 def auto_include @auto_include end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
67 68 69 |
# File 'lib/universal_renderer/configuration.rb', line 67 def http @http end |
#on_error ⇒ Object
Optional callable invoked as call(error, context) when a configured
render fails, where context carries at least :url and :outcome. A
missing url reports :not_configured through the notification only.
Errors are always logged; this exists so they can also reach an exception tracker, since every failure falls back to client rendering silently.
65 66 67 |
# File 'lib/universal_renderer/configuration.rb', line 65 def on_error @on_error end |
#render_path ⇒ Object
Path the blocking renderer is mounted at. Must match the paths.render
option given to createServer, whose default mounts / and /static.
Defaults to nil, meaning the path already in url. A relative value is
treated as absolute, since joining it relatively would replace the last
path segment of url.
34 35 36 |
# File 'lib/universal_renderer/configuration.rb', line 34 def render_path @render_path end |
#sanitize ⇒ Object
Whether ssr_head/ssr_body run the renderer's HTML through Loofah.
SSR::Scrubber is a blocklist, so this is defense in depth over HTML your own renderer produced, not a boundary against attacker-controlled markup. It also parses and rewrites the whole document on every request. On by default, because the cost is bounded and the mistake it catches is not.
47 48 49 |
# File 'lib/universal_renderer/configuration.rb', line 47 def sanitize @sanitize end |
#scrubber ⇒ Object
Scrubber instance used when sanitize is true. Defaults to
SSR::Scrubber; assign your own Loofah::Scrubber to
widen or narrow what survives.
52 53 54 |
# File 'lib/universal_renderer/configuration.rb', line 52 def scrubber @scrubber end |
#stream_path ⇒ Object
Path the streaming renderer is mounted at on the SSR service. Must match
the paths.stream option given to createServer in the NPM package.
Normalized the same way as render_path.
39 40 41 |
# File 'lib/universal_renderer/configuration.rb', line 39 def stream_path @stream_path end |
#timeout ⇒ Object
Open and read timeout, in seconds, for every request to the SSR service.
Keep this above the renderer's own renderTimeout (2.5s by default). A
render that outlives this timeout keeps its concurrency slot until it
finishes, so the renderer must give up first.
26 27 28 |
# File 'lib/universal_renderer/configuration.rb', line 26 def timeout @timeout end |
#url ⇒ Object
Origin of the SSR service, e.g. "http://localhost:3001".
19 20 21 |
# File 'lib/universal_renderer/configuration.rb', line 19 def url @url end |