Class: Closure::Middleware

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

Overview

Although Closure Script can run as an app or in a cascade, most installations will use this Middleware configured with Closure.add_source().

Examples:

config.ru

require 'closure'
Closure.add_source '../src/myapp', '/myapp'
use Closure::Middleware

Instance Method Summary (collapse)

Constructor Details

- (Middleware) initialize(app, home_page = nil)

Returns a new instance of Middleware

Parameters:

  • home_page (String) (defaults to: nil)

    File to serve at the root. Handy for stand-alone projects. You can use a Closure Script, even in non-source folders, by using the url extension e.g. 'index.html' instead of the actual filename 'index.haml'.



30
31
32
33
# File 'lib/closure/middleware.rb', line 30

def initialize(app, home_page=nil)
  @app = app
  @server = ShowExceptions.new(Server.new(Closure.sources, home_page))
end

Instance Method Details

- call(env)



35
36
37
38
39
# File 'lib/closure/middleware.rb', line 35

def call(env)
  status, headers, body = @server.call(env)
  return @app.call(env) if headers["X-Cascade"] == "pass"
  [status, headers, body]
end