Permalink
Browse files

init

  • Loading branch information...
0 parents commit 0a7e6f2189b957c6a3b927f2f9a164d60e20bb6a @adamwiggins committed Dec 21, 2010
Showing with 54 additions and 0 deletions.
  1. +7 −0 example/config.ru
  2. +22 −0 lib/rack/maintenance.rb
  3. +25 −0 readme.md
@@ -0,0 +1,7 @@
+require File.dirname(__FILE__) + '/../lib/rack/maintenance'
+
+use Rack::Maintenance, [503, {'Content-Type'=>'text/plain'}, StringIO.new("Maintenance mode on!\n")]
+
+app = lambda { |env| [200, {'Content-Type'=>'text/plain'}, StringIO.new("If you're seeing this, maintenance mode is turned off and the app is serving pages normally\n")] }
+
+run app
@@ -0,0 +1,22 @@
+module Rack
+ class Maintenance
+ DEFAULT_RESPONSE = [
+ 422,
+ { "Content-Type" => "text/html" },
+ "<body><h2>We are undergoing maintenance right now, please try again later.</h2></body></html>"
+ ]
+
+ def initialize(app, maintenance_response=DEFAULT_RESPONSE)
+ @app = app
+ @maintenance_response = maintenance_response
+ end
+
+ def call(env)
+ if ENV['MAINTENANCE'] == 'on'
+ @maintenance_response
+ else
+ @app.call(env)
+ end
+ end
+ end
+end
@@ -0,0 +1,25 @@
+Simple maintenance mode inserted into your app. Enable with a the MAINTENANCE env var.
+
+# Usage in your rackup file
+
+ require 'lib/rack/maintenance'
+ use Rack::Maintenance
+
+Or provide your own response:
+
+ require 'lib/rack/maintenance'
+ use Rack::Maintenance, [503,{'Content-Type'=>'text/html'}, File.read('public/maintenance.html')]
+
+# Running the example
+
+With maintenance mode off:
+
+ $ cd example
+ $ rackup config.ru
+ $ curl http://localhost:9292
+ If you're seeing this, maintenance mode is turned off and the app is serving pages normally
+
+ $ MAINTENANCE=on rackup config.ru
+ $ curl http://localhost:9292
+ Maintenance mode on!
+

0 comments on commit 0a7e6f2

Please sign in to comment.