Heroku Cedar - 没有安装 Resque 前端的静态资源

发布于 2024-11-24 07:50:34 字数 850 浏览 0 评论 0原文

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

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

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

这很好用,但是当部署到 Heroku 时,Resque 前端的 CSS 和JavaScript 未提供服务。

Heroku 日志的片段表明它返回零字节:

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

如何让它为这些资产提供服务?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

与之呼应 2024-12-01 07:50:35

尝试删除路由并将应用程序安装到 config.ru 中。我正在使用类似的东西:

require ::File.expand_path('../config/environment',  __FILE__)
require 'resque/server'

run Rack::URLMap.new(
    "/" => Rails.application,
    "/resque" => Resque::Server.new 
)

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 
)
﹂绝世的画 2024-12-01 07:50:35

与 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

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
内心旳酸楚 2024-12-01 07:50:35

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

require './app'
run ExampleApp

并在 app.rb 中设置根目录:

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

, 对我来说是一个 sinatra 应用程序。
对于 resque,也许您可​​以扩展该类并安装它,设置根?

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?

﹏半生如梦愿梦如真 2024-12-01 07:50:35

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"

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文