16.02.08

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 :)

By Daniel in development, Snippets2008-02-16 English (EU) Email

4 comments

Comment from: Fueguito [Member] Email
wow sogar die nasa benutzt python
2008-02-17 @ 19:19
Comment from: Walter Cruz [Visitor] Email
Walter CruzPython rulez! (I can't comment using my openid here. b2evo asked for my e-mail and name!)
2008-02-22 @ 13:42
Comment from: Christian Neugebauer [Visitor] Email
Christian NeugebauerRuby example:

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 :-(

2008-03-07 @ 13:00
Comment from: Christian Neugebauer [Visitor] Email
Christian Neugebauershorter,

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.
2008-03-07 @ 16:20

Leave a comment


Your email address will not be revealed on this site.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)
You can just use your OpenID to provide your name, e-mail and url.
Seitenleiste