How do Ruby Goliath applications actually start?

83 views Asked by At

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?

1

There are 1 answers

2
TK-421 On BEST ANSWER

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

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