Skip to content

Instantly share code, notes, and snippets.

@beccasaurus
Created August 27, 2012 01:25
Show Gist options
  • Select an option

  • Save beccasaurus/3484897 to your computer and use it in GitHub Desktop.

Select an option

Save beccasaurus/3484897 to your computer and use it in GitHub Desktop.
Example of how to dispatch requests from 1 Rack application out to different Rack apps
apps = {
'localhost.first' => ->(env) { [200, {'Content-Type' => 'text/plain'}, ['App 1']] },
'localhost.second' => ->(env) { [200, {'Content-Type' => 'text/plain'}, ['App 2']] }
}
run ->(env) do
request = Rack::Request.new(env)
if app = apps[request.host]
app.call(env)
else
[404, {'Content-Type' => 'text/plain'}, ["No app found for host: #{request.host}"]]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment