Search code examples
rubygoliath

How do Ruby Goliath applications actually start?


This is an example from Goliath:

require 'goliath'

class HelloWorld < Goliath::API
  def response(env)
    [200, {}, "hello world"]
  end
end

How does defining a class and subclassing Goliath::API results in a web server being started? Shouldn't this just define a class, not actually instantiate and execute one?


Solution

  • Goliath uses at_exit, not unlike Sinatra, Minitest, etc.

    See some relevant code here, which highlights the additional handling this trick sometimes requires.