class Closure::Middleware

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

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

Public Class Methods

new(app, home_page=nil) click to toggle source

@param (String) home_page 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'.
# 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

Public Instance Methods

call(env) click to toggle source
# 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