module Roda::RodaPlugins::MultiRun

  1. lib/roda/plugins/multi_run.rb

The multi_run plugin provides the ability to easily dispatch to other rack applications based on the request path prefix. First, load the plugin:

class App < Roda
  plugin :multi_run

Then, other rack applications can register with the multi_run plugin: "ra", PlainRackApp "ro", OtherRodaApp "si", SinatraApp

Inside your route block, you can call r.multi_run to dispatch to all three rack applications based on the prefix:

App.route do |r|

This will dispatch routes starting with /ra to PlainRackApp, routes starting with /ro to OtherRodaApp, and routes starting with /si to SinatraApp.

You can pass a block to multi_run that will be called with the prefix, before dispatching to the rack app:

App.route do |r|
  r.multi_run do |prefix|
    # do something based on prefix before the request is passed further

This is useful for modifying the environment before passing it to the rack app.

The multi_run plugin is similar to the multi_route plugin, with the difference being the multi_route plugin keeps all routing subtrees in the same Roda app/class, while multi_run dispatches to other rack apps. If you want to isolate your routing subtrees, multi_run is a better approach, but it does not let you set instance variables in the main Roda app and have those instance variables usable in the routing subtrees.


Public Class

  1. configure

Public Class methods


Initialize the storage for the dispatched applications

[show source]
   # File lib/roda/plugins/multi_run.rb
50 def self.configure(app)
51   app.opts[:multi_run_apps] ||= {}
52 end