Launch a webserver in the current directory
Use case: you want to start a webserver in a given directory, to serve some files from there temporarily.
How many lines of code do you need (including editing config files) to start a webserver in the current directory?
The best answer is probably "one":
python -c "import SimpleHTTPServer; SimpleHTTPServer.test()"
(via comment in "15 Line HTTP server").
Python (with batteries, like web server interfaces, included) is just awesome ![]()
4 comments
ruby -e "require 'webrick'; include WEBrick; s = HTTPServer.new( :DocumentRoot => Dir::pwd ); trap('INT'){s.stop}; s.start"more code, but it's also interesting. The line would be shorter, without the interrupt handling :-(
ruby -e "require 'webrick'; WEBrick::HTTPServer.new( :DocumentRoot => Dir::pwd ).start"but without interrupt handling. For closing the server you must kill the ruby process.
