Module: Roda::RodaPlugins::BridgetownSSR

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

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Class Method Details

.configure(app, _opts = {}) ⇒ Object



43
44
45
46
47
# File 'bridgetown-core/lib/roda/plugins/bridgetown_ssr.rb', line 43

def self.configure(app, _opts = {}, &)
  app.include Bridgetown::Filters::URLFilters
  app.opts[:bridgetown_site] =
    Bridgetown::Site.start_ssr!(loaders_manager: Bridgetown::Rack.loaders_manager, &)
end

.load_dependencies(app, opts = { sessions: false }) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'bridgetown-core/lib/roda/plugins/bridgetown_ssr.rb', line 16

def self.load_dependencies(app, opts = { sessions: false })
  app.plugin :all_verbs
  app.plugin :cookies, path: "/"
  app.plugin :indifferent_params
  app.plugin :method_override
  app.plugin :route_csrf

  # This lets us return callable objects directly in Roda response blocks
  app.plugin :custom_block_results
  app.handle_block_result(Bridgetown::RodaCallable) do |callable|
    request.send :block_result_body, callable.(self)
  end

  return unless opts[:sessions]

  secret_key = ENV.fetch("RODA_SECRET_KEY", nil)
  unless secret_key
    raise Bridgetown::Errors::InvalidConfigurationError,
          "The Roda sessions plugin can't find a valid secret. Run " \
          "`bin/bridgetown secret' and put the key in your ENV as the " \
          "RODA_SECRET_KEY variable"
  end

  app.plugin :sessions, secret: secret_key
  app.plugin :flashier
end