Class: Locomotive::Middlewares::SeoTrailingSlash

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/middlewares/seo_trailing_slash.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}) ⇒ SeoTrailingSlash

Returns a new instance of SeoTrailingSlash.



5
6
7
# File 'lib/locomotive/middlewares/seo_trailing_slash.rb', line 5

def initialize(app, opts = {})
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/locomotive/middlewares/seo_trailing_slash.rb', line 9

def call(env)
  path, query = env['PATH_INFO'], env['QUERY_STRING']

  if !path.starts_with?("#{Locomotive.mounted_on}/") && (match = path.match(%r{(.+)/$}))
    url = self.redirect_url(match[1], query)
    self.redirect_to(url)
  else
    @app.call(env)
  end
end