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

I have a simple Rails application deployed on a Heroku cedar stack.

The app uses Resque and the Resque Sinatra app for the frontend, so I can track the queue:

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

This works fine, but when deploying to Heroku Resque front-end CSS and JavaScript are not supported .

An excerpt from Heroku logs indicates that it returns null 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 him to service these assets?

+6
source share
4 answers

Try to remove the route and install the application in config.ru . I am using something line by line:

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

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 
+5
source

I consider it necessary to establish the root path when deploying to the hero. For example, I download the sinatra application by pointing

 require './app' run ExampleApp 

in config.ru and setting the root in app.rb this way:

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

This solves the problem of static assets that are not served in the sinatra application for me. For resque, perhaps you can extend the class and mount it instead by setting the root?

0
source

The HEROKU stack and cedar need this line of code to prevent a database connection failure.

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

Above code should be placed in: /lib/tasks/resque.rake

For instance:

 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 was for me.

0
source

Source: https://habr.com/ru/post/892693/


All Articles