Class: Cannon::Middleware::Router

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Router

Returns a new instance of Router.



4
5
6
# File 'lib/cannon/middleware/router.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#run(request, response, next_proc) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/cannon/middleware/router.rb', line 8

def run(request, response, next_proc)
  matched_route = @app.routes.find { |route| route.matches? request }
  if matched_route.nil?
    response.not_found
    next_proc.call
  else
    matched_route.handle(request, response, next_proc)
  end
end