If I remembered right, the command below used to be the most voted one on commandlinefu.com:
the “SimpleHTTPServer” module is written in python and it maybe called “the python way”, but that’s not our topic today. what we really want to do here is just making a ruby equivalent for this popular command, using rack.
first, make sure you have rack gem installed on your system (if you’ve installed rails 2.x before, you may already have it):
confirm installation (Rack 1.0 should also work for our example):
Rack 1.1
alright, preparation is done, let’s start cooking. only a rackup file will be sufficient, for consistency, let’s just call it simple_http_server.ru .
#\ -E deployment
use Rack::ContentLength
app = Rack::Directory.new Dir.pwd
run app
Rack::Directory is so awesome that we just simply rely on it… aren’t i cheating? hehe, maybe…
ok, we’re done. to test it, simply run:
and then point your browser to http://locahost:9292/ .
to be useful for daily use, you may consider chmod +x it to make it executable and put it in your $PATH.
$ export PATH=$PATH:`pwd`
to share a directory with your coworkers or friends, simply cd to that directory and execute the script:
$ simple_http_server.ru
since we’re actually using rackup to execute, all the rackup options are also available, which is good:
finally, let’s end up with emulating python SimpleHTTPServer’s default behavior:

on
on
on
on
rack很有名
恩,而且现在很通用
I googled ‘ruby simple http server’, google gave me this link. It is exactly what i want. thank you, samson! haha
Your blog is awesomeeeeeee!!!!
尼玛,好假啊~
i found $python -m SimpleHTTPServer on commandlinefu.com
and for ruby i found this site by google,
thanks.
1 line
rackup -b “run Rack::Directory.new ‘.’”