Module: Bridgetown::Rack

Defined in:
lib/bridgetown-core/rack/boot.rb,
lib/bridgetown-core/rack/logger.rb,
lib/bridgetown-core/rack/routes.rb

Defined Under Namespace

Classes: Logger, Roda, Routes

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.interruptedObject

Returns the value of attribute interrupted.



8
9
10
# File 'lib/bridgetown-core/rack/routes.rb', line 8

def interrupted
  @interrupted
end

.loaders_managerBridgetown::Utils::LoadersManager



29
30
31
# File 'lib/bridgetown-core/rack/boot.rb', line 29

def loaders_manager
  @loaders_manager
end

Class Method Details

.autoload_server_folder(root: Bridgetown::Current.preloaded_configuration.root_dir) ⇒ Object

Parameters:

  • root (String) (defaults to: Bridgetown::Current.preloaded_configuration.root_dir)

    root of Bridgetown site, defaults to config value



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/bridgetown-core/rack/boot.rb', line 51

def self.autoload_server_folder( # rubocop:todo Metrics/MethodLength
  root: Bridgetown::Current.preloaded_configuration.root_dir
)
  server_folder = File.join(root, "server")

  Bridgetown::Hooks.register_one(
    :loader, :post_setup, reloadable: false
  ) do |loader, load_path|
    next unless load_path == server_folder

    loader.eager_load
    loader.do_not_eager_load(File.join(server_folder, "roda_app.rb"))

    unless ENV["BRIDGETOWN_ENV"] == "production"
      Listen.to(server_folder) do |_modified, _added, _removed|
        loader.reload
        loader.eager_load
        Bridgetown::Rack::Routes.reload_subclasses
      rescue SyntaxError => e
        Bridgetown::Errors.print_build_error(e)
      end.start
    end
  end

  Bridgetown::Hooks.register_one(
    :loader, :post_reload, reloadable: false
  ) do |loader, load_path|
    next unless load_path == server_folder

    loader.eager_load
    Bridgetown::Rack::Routes.reload_subclasses
  end

  loaders_manager.setup_loaders([server_folder])
end

.bootObject

Start up the Roda Rack application and the Zeitwerk autoloaders. Ensure the Roda app is provided the preloaded Bridgetown site configuration. Handle any uncaught Roda errors.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bridgetown-core/rack/boot.rb', line 35

def self.boot(*)
  self.loaders_manager =
    Bridgetown::Utils::LoadersManager.new(Bridgetown::Current.preloaded_configuration)
  Bridgetown::Current.preloaded_configuration.run_initializers! context: :server
  autoload_server_folder
rescue Roda::RodaError => e
  if e.message.include?("sessions plugin :secret option")
    raise Bridgetown::Errors::InvalidConfigurationError,
          "The Roda sessions plugin can't find a valid secret. Run `bin/bridgetown secret' " \
          "and put the key in a ENV var you can use to configure the session in the Roda app"
  end

  raise e
end