Skip to content

Instantly share code, notes, and snippets.

@jch
Created April 30, 2012 05:16
Show Gist options
  • Save jch/2555714 to your computer and use it in GitHub Desktop.
Save jch/2555714 to your computer and use it in GitHub Desktop.
Programmatically start a rack app
require 'rack'
class RackApp
def self.call(env)
[200, {'Content-Type' => 'text/html'}, ['derp']]
end
end
# For a full list of options, see
# http://www.ruby-doc.org/stdlib-1.9.3/libdoc/webrick/rdoc/WEBrick.html
options = {
:Host => '127.0.0.1',
:Port => '3000'
}
Rack::Handler::WEBrick.run(RackApp, options) do |server|
[:INT, :TERM].each { |sig| trap(sig) { server.stop } }
end
@sheldonh
Copy link

sheldonh commented Feb 5, 2018

@radfahrer WEBrick is part of the Ruby standard library, so it's always available. That's nice for test suites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment