【问题标题】:Heroku Cedar - no static assets for mounted Resque front-endHeroku Cedar - 安装的 Resque 前端没有静态资产
【发布时间】:2011-10-04 15:59:19
【问题描述】:

我有一个简单的 Rails 应用程序部署到 Heroku Cedar 堆栈。

该应用程序使用 Resque,并且安装了 Resque Sinatra 前端应用程序,因此我可以监控队列:

# routes.rb
...
mount Resque::Server, :at => "/resque"

这很好用,但是当部署到 Heroku 时,Resque front-end's CSS & JavaScript 没有被提供服务。

Heroku 日志的 sn-p 表明它返回零字节:

...
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

我怎样才能让它为这些资产提供服务?

【问题讨论】:

    标签: ruby-on-rails ruby heroku resque


    【解决方案1】:

    HEROKU Cedar stack 和rescue 需要这行代码来防止数据库连接失败。

    Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }
    

    以上代码应放在:/lib/tasks/resque.rake

    例如:

    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"
    

    希望这对某人有所帮助,就像对我一样。

    【讨论】:

      【解决方案2】:

      与 ezkl 相同,但受密码保护,适用于我:

      # 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
      

      【讨论】:

      • 感谢 kain,好建议。但是,我决定在我的 resque.rb 初始化程序中定义我的身份验证,如下所示:# use basic auth on the resque front-end Resque::Server.use(Rack::Auth::Basic) do |user, password| password == "secret" end
      【解决方案3】:

      尝试删除路由并将应用程序安装在您的config.ru 中。我正在使用以下内容:

      require ::File.expand_path('../config/environment',  __FILE__)
      require 'resque/server'
      
      run Rack::URLMap.new(
          "/" => Rails.application,
          "/resque" => Resque::Server.new 
      )
      

      【讨论】:

        【解决方案4】:

        我认为在部署到 heroku 时有必要设置根路径。例如,我通过指定来启动一个 sinatra 应用程序

        require './app'
        run ExampleApp
        

        config.ru 中,并在app.rb 中设置根:

        class ExampleApp < Sinatra::Base
          set :root, File.dirname(__FILE__)
        end
        

        对我来说,这解决了静态资产无法在 sinatra 应用程序中提供的问题。 对于 resque,也许您可​​以扩展类并安装它,设置根目录?

        【讨论】:

        • 感谢tiredpixel,很高兴知道这个选项以备将来使用。
        猜你喜欢
        • 2011-09-21
        • 1970-01-01
        • 1970-01-01
        • 2012-06-13
        • 2013-05-29
        • 1970-01-01
        • 1970-01-01
        • 2016-02-04
        • 1970-01-01
        相关资源
        最近更新 更多