Heroku Cedar - no static assets for mounted Resque front-end
I have a simple Rails app deployed to the Heroku Cedar stack.
The app uses Resque and the Resque Sinatra front-end app is mounted so I can monitor the queue:
# routes.rb
...
mount Resque::Server, :at => "/resque"
This works great, but when deployed to Heroku, the Resque front-end's CSS & JavaScript are not being served.
A snippet of Heroku's logs indicates it's return开发者_开发百科ing zero bytes:
...
2011-07-13T16:19:35+00:00 heroku[router]: GET myapp.herokuapp.com/resque/style.css dyno=web.1 queue=0 wait=0ms service=3ms status=200 bytes=0
2011-07-13T16:19:35+00:00 app[web.1]:
2011-07-13T16:19:35+00:00 app[web.1]:
2011-07-13T16:19:35+00:00 app[web.1]: Started GET "/resque/style.css" for 87.xx.xx.xx at 2011-07-13 16:19:35 +0000
2011-07-13T16:19:35+00:00 app[web.1]: cache: [GET /resque/style.css] miss
How can I get it to serve these assets?
Try removing the route and mounting the app in your config.ru
. I'm using something along the lines of:
require ::File.expand_path('../config/environment', __FILE__)
require 'resque/server'
run Rack::URLMap.new(
"/" => Rails.application,
"/resque" => Resque::Server.new
)
Same as ezkl but password protected, works for me:
# config.ru
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
require 'resque/server'
# Set the AUTH env variable to your basic auth password to protect Resque.
AUTH_PASSWORD = ENV['RESQUE_PASSWORD']
if AUTH_PASSWORD
Resque::Server.use Rack::Auth::Basic do |username, password|
password == AUTH_PASSWORD
end
end
run Rack::URLMap.new \
'/' => MyApp::Application,
'/resque' => Resque::Server.new
I believe it's necessary to set a root path, when deploying to heroku. For example, I boot a sinatra application by specifying
require './app'
run ExampleApp
in config.ru
, and setting the root in app.rb
thus:
class ExampleApp < Sinatra::Base
set :root, File.dirname(__FILE__)
end
That solves the problem of static assets not being served in a sinatra application, for me. For resque, perhaps you can extend the class and mount that instead, setting the root?
HEROKU Cedar stack and rescue need this line of code to prevent database connection failure.
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }
Above code should be placed in: /lib/tasks/resque.rake
For example:
require 'resque/tasks'
task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
Resque.after_fork do |job|
ActiveRecord::Base.establish_connection
end
end
desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"
Hope this helps someone, as much as it did for me.
精彩评论