Class: UniversalRenderer::Client::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/universal_renderer/client/base.rb

Overview

Fetches server-side rendered (SSR) content from the Node.js service in a single, blocking request. This client is used when SSR content is needed in its entirety before the Rails view rendering proceeds, as opposed to streaming SSR.

Class Method Summary collapse

Class Method Details

.call(url, props) ⇒ UniversalRenderer::SSR::Response?

Performs a POST request to the SSR service to retrieve the complete SSR content. This is used for non-streaming SSR, where the entire payload is fetched before the main application view is rendered.

Emits a render.universal_renderer notification for every attempt and routes failures through config.on_error.

Parameters:

  • url (String)

    The URL of the page to render on the SSR server. This should typically be the request.original_url from the controller.

  • props (Hash)

    A hash of props to be passed to the SSR service. These props will be available to the frontend components for rendering.

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/universal_renderer/client/base.rb', line 30

def self.call(url, props)
  config = UniversalRenderer.config
  ssr_url = config.url

  Instrumentation.instrument(url: url, mode: :blocking) do |event|
    if ssr_url.blank?
      event[:outcome] = :not_configured
      next nil
    end

    perform(ssr_url, config, url, props, event)
  end
end