Module: Rodbot::Rack

Defined in:
lib/rodbot/rack.rb

Class Method Summary collapse

Class Method Details

.boot(rack) ⇒ Object

Default config.ru

In case you wish to do things differently, just copy the contents of this method into your config.ru file and tweak it.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rodbot/rack.rb', line 16

def boot(rack)
  loader = Zeitwerk::Loader.new
  loader.logger = Rodbot::Log.logger('loader')
  loader.push_dir(Rodbot.env.root.join('lib'))
  loader.push_dir(Rodbot.env.root.join('app'))

  if Rodbot.env.development? || Rodbot.env.test?
    loader.enable_reloading
    loader.setup
    rack.run ->(env) do
      loader.reload
      App.call(env)
    end
  else
    loader.setup
    Zeitwerk::Loader.eager_load_all
    rack.run App.freeze.app
  end
end

.request(path, params: {}, timeout: 10) ⇒ HTTPX::Response

Send request to the app service

Parameters:

  • path (String)

    path e.g. /help

  • params (Hash) (defaults to: {})

    params hash e.g. { search: ‘foobar’ }

  • timeout (Integer) (defaults to: 10)

    max seconds to wait for response

Returns:

  • (HTTPX::Response)


42
43
44
# File 'lib/rodbot/rack.rb', line 42

def request(path, params: {}, timeout: 10)
  HTTPX.with(timeout: { request_timeout: timeout }).get(Rodbot::Services::App.url.uri_concat(path), params: params)
end