Class: Cup::Server::Middleware

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



7
8
9
10
# File 'lib/cup/server/middleware.rb', line 7

def initialize app
  @app = app
  @directory = Rack::Directory.new(Cup::Directory.current.path)
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cup/server/middleware.rb', line 12

def call(env)

  status, headers, response = @app.call(env)

  if status == 404
    directory_status, *result = @directory.call(env)
    if (200...300).include? directory_status
      status, headers, response = directory_status, *result
    end
  end

  [status, headers, response]
end