Created
August 27, 2012 01:25
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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