Skip to content

Instantly share code, notes, and snippets.

@asaaki
Last active December 11, 2015 05:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asaaki/4555029 to your computer and use it in GitHub Desktop.
Save asaaki/4555029 to your computer and use it in GitHub Desktop.
Simple Rack setup where you can move your middleware and map config to another file
App = lambda do |env|
[
200,
{ "Content-Type" => "text/plain" },
[
"Hello!\n",
"self in config.ru is: #{RACK_BUILDER.to_s}\n",
"@use = #{RACK_BUILDER.instance_variable_get(:@use)}\n",
"@map = #{RACK_BUILDER.instance_variable_get(:@map)}\n",
]
]
end
$LOAD_PATH.unshift('.')
# bind this instance to a constant
RACK_BUILDER = self
require 'app'
require 'routes'
RACK_BUILDER.instance_exec do
# use, map and run are working here
use Rack::Lock
map '/subtest' do
run App
end
end
@markrambow
Copy link

easy :) I like
Should make it easier for development at least

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment