Class: RailsWithRelativeUrlRoot

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_with_relative_url_root.rb,
lib/rails_with_relative_url_root/version.rb

Constant Summary collapse

VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.applicationObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rails_with_relative_url_root.rb', line 6

def self.application
  Rack::Builder.app do
    relative_url_root = Rails.application.config.relative_url_root

    if relative_url_root.present?
      use Rack::Rewrite do
        r301 '/', relative_url_root

        if File.exists?(File.join(Rails.root, 'public', 'robots.txt'))
          rewrite '/robots.txt', relative_url_root + '/robots.txt'
        end
      end

      map relative_url_root do
        run Rails.application
      end
    else
      run Rails.application
    end
  end
end