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

Defined in:
bridgetown-core/lib/roda/plugins/bridgetown_server.rb

Instance Method Summary collapse

Instance Method Details

#initialize_bridgetown_contextObject



110
111
112
113
114
115
116
117
118
119
# File 'bridgetown-core/lib/roda/plugins/bridgetown_server.rb', line 110

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



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 121

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

    status, headers, body = self.class.opts[:ssg_server].serving(
      request, File.join(self.class.opts[:ssg_root], "index.html")
    )
    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 find <code>index.html</code> in the output folder.</p>"
  end
end