module Quilt::ReactRenderable
Public Instance Methods
render_react(headers: {}, data: {})
click to toggle source
# File lib/quilt_rails/react_renderable.rb, line 9 def render_react(headers: {}, data: {}) if Rails.env.test? && !Quilt.configuration.allow_integration_test raise DoNotIntegrationTestError end # Allow concurrent loading to prevent this thread from blocking class # loading in controllers called by the Node server. ActiveSupport::Dependencies.interlock.permit_concurrent_loads do call_proxy(headers, data) end end
Private Instance Methods
call_proxy(headers, data)
click to toggle source
# File lib/quilt_rails/react_renderable.rb, line 23 def call_proxy(headers, data) if defined? ShopifySecurityBase allowlist = ShopifySecurityBase::HTTPHostRestriction.respond_to?(:allowlist) ? :allowlist : :whitelist ShopifySecurityBase::HTTPHostRestriction.send(allowlist, [Quilt.configuration.react_server_host]) do proxy(headers, data) end else proxy(headers, data) end end
proxy(headers, data)
click to toggle source
# File lib/quilt_rails/react_renderable.rb, line 34 def proxy(headers, data) url = "#{Quilt.configuration.react_server_protocol}://#{Quilt.configuration.react_server_host}" Quilt.logger.info("[ReactRenderable] proxying to React server at #{url}") unless headers.blank? Quilt.logger.info("[ReactRenderable] applying custom headers #{headers.inspect}") end begin reverse_proxy( url, headers: headers.merge('X-Request-ID': request.request_id, 'X-Quilt-Data': data.to_json) ) do |callbacks| callbacks.on_response do |status_code, _response| Quilt.logger.info("[ReactRenderable] #{url} returned #{status_code}") end end rescue Errno::ECONNREFUSED raise ReactServerNoResponseError, url end end