Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Using casino with a non-root URL (apache, passenger, rails 4.1) does not work out of the box #51

Closed
swobspace opened this issue Jun 22, 2014 · 2 comments

Comments

@swobspace
Copy link

Casino works fine for me with rails 4.1 (branch rails4) if the casino application uses the root url, but there are some gotchas if I install casino (using a simple new plain rails 4.1 app) for use on a sub url like myhost.example.net/zas. We use a lot of applications through a reverse proxy, so each application including casino has to use a sub url to separate namespaces.

Here is what I have done to get it working using /zas as sub url:

# /etc/apache2/conf.d/zas.conf
<Location /zas>
  PassengerBaseURI /zas
  PassengerAppRoot /var/srv/www/casinoapp/current
  RackEnv production
</Location>

<Directory "/var/srv/www/casinoapp/current/public">
   AllowOverride All
   order allow,deny
   allow from all
</Directory>
# casinoapp/config/application.rb:
Rails.application.routes.default_url_options[:script_name] = ENV['RAILS_RELATIVE_URL_ROOT']

I've got the idea for the default_url_options from here: activeadmin/activeadmin#101 (comment)

There is a special issue with redirects in routes.rb within an engine, for rails4 I use the following modification to casino/config/routes.rb:

  root to: redirect('login')

Just remove the '/' from '/login' here. Rails4 then respects SCRIPT_NAME for sub urls. More info on this: rails/rails#7977 (comment)

And last but not least asset precompilation must respect the sub url on deployment:

namespace :deploy do
  namespace :assets do
    task :precompile do
      run "cd #{release_path} && bundle exec rake RAILS_ENV=production RAILS_RELATIVE_URL_ROOT=#{sub_uri} assets:precompile"
    end
  end
end
before 'deploy:assets:precompile', 'deploy:assets:symlink'

The only issue here for casino (using the current rails 4 branch and rails 4.1) is the '/' in front of login which should be removed.

# root to: redirect('/login')
root to: redirect('login')

The other stuff can be done by using a own minimal rails application instead of CASinoApp.

@pencil
Copy link
Member

pencil commented Jun 25, 2014

Thank you for your analysis! I'll probably have some time to work on CASino next week. The proposed solution seems reasonable and I don't think it will break anything.

@pencil pencil closed this as completed in 12b5073 Jul 19, 2014
@swobspace
Copy link
Author

Thanx. Works great for me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants