Ruby Rack - mounting a simple web server that reads index.html as default
I think that you are missing the the rackup command. Here is how it is used:
rackup config.ru
This is going to run your rack app on port 9292 using webrick. You can read "rackup --help" for more info how you can change these defaults.
About the app that you want to create. Here is how I think it should look like:
# This is the root of our app@root = File.expand_path(File.dirname(__FILE__))run Proc.new { |env| # Extract the requested path from the request path = Rack::Utils.unescape(env['PATH_INFO']) index_file = @root + "#{path}/index.html" if File.exists?(index_file) # Return the index [200, {'Content-Type' => 'text/html'}, File.read(index_file)] # NOTE: using Ruby >= 1.9, third argument needs to respond to :each # [200, {'Content-Type' => 'text/html'}, [File.read(index_file)]] else # Pass the request to the directory app Rack::Directory.new(@root).call(env) end}
I ended up on this page looking for a one liner...
If all you want is to serve the current directory for a few one-off tasks, this is all you need:
ruby -run -e httpd . -p 5000
Details on how it works: http://www.benjaminoakes.com/2013/09/13/ruby-simple-http-server-minimalist-rake/