Method: Sinatra::Base.run!

Defined in:
lib/sinatra/base.rb

.run!(options = {}, &block) ⇒ Object Also known as: start!

Run the Sinatra app as a self-hosted server using Puma, Falcon (in that order). If given a block, will call with the constructed handler once we have taken the stage.

[View source]

1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
# File 'lib/sinatra/base.rb', line 1606

def run!(options = {}, &block)
  unless defined?(Rackup::Handler)
    rackup_warning = <<~MISSING_RACKUP
      Sinatra could not start, the required gems weren't found!

      Add them to your bundle with:

          bundle add rackup puma

      or install them with:

          gem install rackup puma

    MISSING_RACKUP
    warn rackup_warning
    exit 1
  end

  return if running?

  set options
  handler         = Rackup::Handler.pick(server)
  handler_name    = handler.name.gsub(/.*::/, '')
  server_settings = settings.respond_to?(:server_settings) ? settings.server_settings : {}
  server_settings.merge!(Port: port, Host: bind)

  begin
    start_server(handler, server_settings, handler_name, &block)
  rescue Errno::EADDRINUSE
    warn "== Someone is already performing on port #{port}!"
    raise
  ensure
    quit!
  end
end