Module: Roda::RodaPlugins::BridgetownServer::InstanceMethods

Includes:
Bridgetown::Refinements::Helper
Defined in:
bridgetown-core/lib/roda/plugins/bridgetown_server.rb

Instance Method Summary collapse

Methods included from Bridgetown::Refinements::Helper

#refine

Instance Method Details

#deconstruct_keysObject

This is useful if you’re passing the Roda app instance around and want to get at request / response easily as local variables



142
143
144
# File 'bridgetown-core/lib/roda/plugins/bridgetown_server.rb', line 142

def deconstruct_keys(*)
  { request:, response: }
end

#initialize_bridgetown_contextObject



107
108
109
110
111
112
113
114
115
116
# File 'bridgetown-core/lib/roda/plugins/bridgetown_server.rb', line 107

def initialize_bridgetown_context
  if self.class.opts[:bridgetown_site]
    # The site had previously been initialized via the bridgetown_ssr plugin
    Bridgetown::Current.sites[self.class.opts[:bridgetown_site].label] =
      self.class.opts[:bridgetown_site]
    @context ||= SiteContext.new({ site: self.class.opts[:bridgetown_site] })
  end
  Bridgetown::Current.preloaded_configuration ||=
    self.class.opts[:bridgetown_preloaded_config]
end

#initialize_bridgetown_rootObject

rubocop:todo Metrics/AbcSize



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'bridgetown-core/lib/roda/plugins/bridgetown_server.rb', line 118

def initialize_bridgetown_root # rubocop:todo Metrics/AbcSize
  request.root do
    hook_result = instance_exec(&self.class.opts[:root_hook]) if self.class.opts[:root_hook]
    next hook_result if hook_result

    root_file = [
      File.join(self.class.opts[:ssg_root], "index.html"),
      File.expand_path("generic_index.html", __dir__),
    ].find { File.exist?(_1) }

    status, headers, body = self.class.opts[:ssg_server].serving(request, root_file)
    response_headers = response.headers
    response_headers.replace(headers)

    request.halt [status, response_headers, body]
  rescue StandardError => e
    Bridgetown.logger.debug("Root handler error: #{e.message}")
    response.status = 500
    "<p>ERROR: cannot serve the root <code>index</code> file.</p>"
  end
end