You need to use Rack::Builder to use the use SomeMiddleware syntax in a regular Ruby script (it is usually used in config.ru ). You will also need run for your application. Note that the urls key on Rack::Static accepts an array, not a single line:
require 'rack' Rack::Handler::Thin.run(Rack::Builder.new { use(Rack::Static, urls: ["/resource/"], root: "/") run ->env{[200, {}, [some_dyamically_generated_content]]} }, Port: 3000)
Here Rack::Builder takes your application, ->env{[200, {}, [some_dyamically_generated_content]]} , adding Rack::Static middleware to it and creating a new combo application that is then passed to Thin for launch.
Rack::Static is a middleware component that can be added to existing rack applications. Rack::File and Rack::Directory are the rack applications themselves, not middleware ( Rack::Static uses Rack::File internally, just like Rack::Directory by default). You can achieve the same effect as above using the Rack::File and map command:
require 'rack' Rack::Handler::Thin.run(Rack::Builder.new { map "/resource/" do run Rack::File.new "/" end map "/" do run ->env{[200, {}, [some_dyamically_generated_content]]} end }, Port: 3000)
A more common way to do this is to place the contents of the block passed to Rack::Bundler.new in the config.ru file:
use(Rack::Static, urls: ["/resource/"], root: "/") run ->env{[200, {}, [some_dyamically_generated_content]]}
Then you can start this with thin start , which should be found by config.ru if it starts from the same directory, or you can use the -R option to specify the file. The rackup command rackup also be used by rackup -s thin if you want to specify Thin as the server.