Created
April 30, 2012 05:16
-
-
Save jch/2555714 to your computer and use it in GitHub Desktop.
Programmatically start a rack app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
@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
Thank you @jch! It's taken me quite a bit of searching to find this gem of an example. You have made my day. I do wonder why you chose WEBrick?