could someone give me a hint, howto serve the current directory from command line with ruby? it would be great, if i can have some system wide configuration (e.g. mime-types) and simply launch it from every directory.
A:
Web Server in 1 line
This may or may not be quite what you want but it's so cool that I just had to share it.
I've used this in the past to serve the file system. Perhaps you could modify it or just accept that it serves everything.
ruby -rsocket -e 's=TCPServer.new(5**5);loop{_=s.accept;_<<"HTTP/1.0 200 OK\r\n\r\n#{File.read(_.gets.split[1])rescue nil}";_.close}'
I found it here
Chris
Chris McCauley
2010-06-24 08:49:55
A:
I've never seen anything as compact as
python -m SimpleHTTPServer
for Ruby, Chris' answer shows up several times on Google.
Michael Kohl
2010-06-24 11:36:36
+1
A:
require 'webrick'
include WEBrick
s = HTTPServer.new(:Port => 9090,
:DocumentRoot => Dir::pwd + "/htdocs")
trap("INT"){ s.shutdown }
s.start
Chris G.
2010-06-24 18:24:19