Browse files

Add -N or --no-default-middleware option.

This would prevent Unicorn from adding default middleware,
as if RACK_ENV were always none. (not development nor deployment)

This should also be applied to `rainbows' and `zbatery' as well.

One of the reasons to add this is to avoid conflicting
RAILS_ENV and RACK_ENV. It would be helpful in the case
where a Rails application and Rack application are composed
together, while we want Rails app runs under development
and Rack app runs under none (if we don't want those default
middleware), and we don't really want to make RAILS_ENV
set to development and RACK_ENV to none because it might be
confusing. Note that Rails would also look into RACK_ENV.

Another reason for this is that only `rackup' would be
inserting those default middleware. Both `thin' and `puma'
would not do this, nor does Rack::Handler.get.run which is
used in Sinatra.

So using this option would make it work differently from
`rackup' but somehow more similar to `thin' or `puma'.

Discussion thread on the mailing list:
http://rubyforge.org/pipermail/mongrel-unicorn/2013-January/001675.html

Signed-off-by: Eric Wong <normalperson@yhbt.net>
  • Loading branch information...
1 parent fdd7c85 commit c43113e350aabb78c30ba64884328458db85c901 @godfat godfat committed with Eric Wong Jan 29, 2013
Showing with 7 additions and 0 deletions.
  1. +5 −0 bin/unicorn
  2. +2 −0 lib/unicorn.rb
View
5 bin/unicorn
@@ -58,6 +58,11 @@ op = OptionParser.new("", 24, ' ') do |opts|
ENV["RACK_ENV"] = e
end
+ opts.on("-N", "--no-default-middleware",
+ "do not load middleware implied by RACK_ENV") do |e|
+ rackup_opts[:no_default_middleware] = true
+ end
+
opts.on("-D", "--daemonize", "run daemonized in the background") do |d|
rackup_opts[:daemonize] = !!d
end
View
2 lib/unicorn.rb
@@ -49,6 +49,8 @@ def self.builder(ru, op)
pp({ :inner_app => inner_app }) if $DEBUG
+ return inner_app if op[:no_default_middleware]
+
# return value, matches rackup defaults based on env
# Unicorn does not support persistent connections, but Rainbows!
# and Zbatery both do. Users accustomed to the Rack::Server default

0 comments on commit c43113e

Please sign in to comment.