Heroku Cedar – 没有安装Resque前端的静态资产
我有一个简单的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
我怎样才能让它服务这些资产?
尝试删除路线并在config.ru
安装应用程序。 我正在使用以下内容:
require ::File.expand_path('../config/environment', __FILE__) require 'resque/server' run Rack::URLMap.new( "/" => Rails.application, "/resque" => Resque::Server.new )
与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
我相信在部署到heroku时需要设置根路径。 例如,我通过指定启动sinatra应用程序
require './app' run ExampleApp
在config.ru
,并在app.rb
设置root:
class ExampleApp < Sinatra::Base set :root, File.dirname(__FILE__) end
这解决了我在sinatra应用程序中没有提供静态资产的问题。 对于resque,也许你可以扩展类并安装它,而不是设置root?
HEROKU Cedar堆栈和救援需要这行代码来防止数据库连接失败。
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"
希望这能帮助某人,就像它对我一样。
- 如何在生产轨道中给出指纹css路径4
- GET请求(无JSON)无法使用Rails 4.1上的Devise 3.2.4validationCSRF令牌的真实性
- Heroku Force Clear Varnish Cache
- Heroku上的Rails 4应用程序是500,但日志中没有错误消息
- 使用Rails 5在Heroku,PostgreSQL上运行迁移时出错
- Rails,Heroku和Resque:长时间运行的背景作业优化
- Rails 3.1 Sqlite3错误推送到Heroku
- 我可以在heroku中托管图像吗? 或者我需要S3?
- Heroku推送错误:rake资产上的“NameError:未初始化的常量Uglifier :: VERSION”:预编译