about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-11-11 19:29:57 -0800
committerEric Wong <normalperson@yhbt.net>2009-11-11 19:29:57 -0800
commit4770ea6d7a6eaf00cc19bc4fb2afd59071e8cf66 (patch)
treec8b19747254a4c0cc48511bfae8b502452e44120
parentcb90269157aeda3655b1a12ea7be4666c98a5e2c (diff)
downloadupr-4770ea6d7a6eaf00cc19bc4fb2afd59071e8cf66.tar.gz
examples/rails_app-2.3.4: move middleware setup to config.ru
config.ru is more obvious and easier to use with non-Rails
applications.  This is true especially if you want to share
the Upr::Monitor object/connection with the upcoming
Upr::Streaming JSON application.
-rw-r--r--examples/rails_app-2.3.4/config.ru15
-rw-r--r--examples/rails_app-2.3.4/config/environment.rb10
2 files changed, 20 insertions, 5 deletions
diff --git a/examples/rails_app-2.3.4/config.ru b/examples/rails_app-2.3.4/config.ru
index d51b6b2..dcd7fb5 100644
--- a/examples/rails_app-2.3.4/config.ru
+++ b/examples/rails_app-2.3.4/config.ru
@@ -1,3 +1,14 @@
 require 'config/environment'
-use Rails::Rack::Static
-run ActionController::Dispatcher.new
+# upr defaults to using a Moneta::Memory backend which is good enough
+# for single-process/server applications
+$upr = Upr::Monitor.new
+
+map "/" do
+  use Rack::Chunked
+  use Rack::ContentLength
+  use Rack::Deflater
+
+  use Upr, :backend => $upr, :frequency => 1
+  use Rails::Rack::Static
+  run ActionController::Dispatcher.new
+end
diff --git a/examples/rails_app-2.3.4/config/environment.rb b/examples/rails_app-2.3.4/config/environment.rb
index c323778..f2670b8 100644
--- a/examples/rails_app-2.3.4/config/environment.rb
+++ b/examples/rails_app-2.3.4/config/environment.rb
@@ -25,8 +25,12 @@ Rails::Initializer.run do |config|
 
   # We MUST insert Upr before any parsers that read the body
   # since we need to wrap all calls to "rack.input"
-  config.middleware.insert_before('ActionController::ParamsParser',
-       'Upr',
+  # It is usually easier to just load it in RAILS_ROOT/config.ru
+  # (which is what we did, but here is a commented example of using
+  # upr inside the Rails middleware stack):
+  #
+  # config.middleware.insert_before('ActionController::ParamsParser',
+       # 'Upr',
        # The default is to use the Moneta::Memory store here.
        # This won't work right if you have multiple processes
        # serving your application, however.
@@ -48,5 +52,5 @@ Rails::Initializer.run do |config|
        # :drb => 'druby://127.0.0.1:2999',
        #
        # Update at most once every second (default is every 3 seconds)
-       :frequency => 1)
+       # :frequency => 1)
 end