Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.
This repository was 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

@swobspace

Description

@swobspace

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions