Class: Locomotive::Middlewares::SeoTrailingSlash

Inherits:
Base
  • 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
19
20
# File 'lib/locomotive/middlewares/seo_trailing_slash.rb', line 9

def call(env)
  request = Rack::Request.new(env)

  path = request.path

  if !is_backoffice?(request) && path.size > 1 && path.ends_with?('/')
    url = modify_url(request, request.path.chop)
    redirect_to(url)
  else
    @app.call(env)
  end
end