Class: WWWRedirect::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/www_redirect/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



3
4
5
# File 'lib/www_redirect/middleware.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/www_redirect/middleware.rb', line 7

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

  unless request.host.index(/^www\./)
    [301, {"Location" => build_path(request)}, []]
  else
    @app.call(env)
  end
end