Heroku Cedar - no static assets for mounted Resque front-end

我怕爱的太早我们不能终老 提交于 2019-12-07 04:37:59

问题


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 returning 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?


回答1:


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 
)



回答2:


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



回答3:


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?




回答4:


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.



来源:https://stackoverflow.com/questions/6682265/heroku-cedar-no-static-assets-for-mounted-resque-front-end

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!