Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 17th, 2012  |  syntax: None  |  size: 0.66 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # https://gist.github.com/1214052
  2. require 'sinatra/base'
  3.  
  4. class ResqueWeb < Sinatra::Base
  5.   require 'resque/server'
  6.   use Rack::ShowExceptions
  7.  
  8.   if CFG[:user].present? and CFG[:password].present?
  9.     Resque::Server.use Rack::Auth::Basic do |user, password|
  10.       user == CFG[:user] && password == CFG[:password]
  11.     end
  12.   end
  13.  
  14.   def call(env)
  15.     @server ||= Resque::Server.new
  16.     status, headers, body = @server.call(env)
  17.  
  18.     # in production/staging with nginx, assets always hang endless <-> this fixes it
  19.     if body.is_a? Sinatra::Helpers::StaticFile
  20.       buffer = []
  21.       body.each{|x| buffer << x }
  22.       body = buffer
  23.     end
  24.  
  25.     [status, headers, body]
  26.   end
  27. end