Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a rackup option for one-liner rack app server

  • Loading branch information...
commit 3edd1e8e0e85c888cb61130f8a0e28db88bd5787 1 parent 6d41179
@udzura authored
Showing with 25 additions and 9 deletions.
  1. +19 −9 lib/rack/server.rb
  2. +6 −0 test/spec_server.rb
View
28 lib/rack/server.rb
@@ -17,6 +17,10 @@ def parse!(args)
lineno += 1
}
+ opts.on("-b", "--builder BUILDER_LINE", "evaluate a BUILDER_LINE of code as a builder script") { |line|
+ options[:builder] = line
+ }
+
opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") {
options[:debug] = true
}
@@ -192,15 +196,7 @@ def default_options
end
def app
- @app ||= begin
- if !::File.exist? options[:config]
- abort "configuration #{options[:config]} not found"
- end
-
- app, options = Rack::Builder.parse_file(self.options[:config], opt_parser)
- self.options.merge! options
- app
- end
+ @app ||= options[:builder] ? build_app_from_string : build_app_and_options_from_config
end
def self.logging_middleware
@@ -273,6 +269,20 @@ def server
end
private
+ def build_app_and_options_from_config
+ if !::File.exist? options[:config]
+ abort "configuration #{options[:config]} not found"
+ end
+
+ app, options = Rack::Builder.parse_file(self.options[:config], opt_parser)
+ self.options.merge! options
+ app
+ end
+
+ def build_app_from_string
+ Rack::Builder.new_from_string(self.options[:builder])
+ end
+
def parse_options(args)
options = default_options
View
6 test/spec_server.rb
@@ -22,6 +22,12 @@ def with_stderr
server.app.should == "FOO"
end
+ should "prefer to use :builder when it is passed in" do
+ server = Rack::Server.new(:builder => "run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['success']] }")
+ server.app.class.should == Proc
+ Rack::MockRequest.new(server.app).get("/").body.to_s.should.equal 'success'
+ end
+
should "not include Rack::Lint in deployment or none environments" do
server = Rack::Server.new(:app => 'foo')
server.middleware['deployment'].flatten.should.not.include(Rack::Lint)
Please sign in to comment.
Something went wrong with that request. Please try again.