Module: Roda::RodaPlugins::Middleware

Defined in:
lib/roda/plugins/middleware.rb

Overview

The middleware plugin allows the Roda app to be used as rack middleware.

In the example below, requests to /mid will return Mid by the Mid middleware, and requests to /app will not be matched by the Mid middleware, so they will be forwarded to App.

class Mid < Roda
  plugin :middleware

  route do |r|
    r.is "mid" do
      "Mid"
    end
  end
end

class App < Roda
  use Mid

  route do |r|
    r.is "app" do
      "App"
    end
  end
end

run App

It is possible to use the Roda app as a regular app even when using the middleware plugin.

Defined Under Namespace

Modules: ClassMethods, RequestMethods Classes: Forwarder

Class Method Summary collapse

Class Method Details

.configure(app, opts = {}) ⇒ Object

Configure the middleware plugin. Options:

:env_var

Set the environment variable to use to indicate to the roda application that the current request is a middleware request. You should only need to override this if you are using multiple roda middleware in the same application.



44
45
46
47
# File 'lib/roda/plugins/middleware.rb', line 44

def self.configure(app, opts={})
  app.opts[:middleware_env_var] = opts[:env_var] if opts.has_key?(:env_var)
  app.opts[:middleware_env_var] ||= 'roda.forward_next'
end