The Guerilla Hack Chronicles: Dancer as a Ad-Hoc Web Server
The Guerilla Hack Chronicles: Dancer as a Ad-Hoc Web Server
edit (March 14th, 2011): even better suggestions from the comments have been added at the end of the entry.
Let’s say you want to serve static http content from a machine. The sensible thing to do would be to install Apache/Nginx/Lighttp.
But let’s say — because of insane configuration, red tapes, cruel whims of the gods — that you can’t do the sensible thing.
Fortunately, there’s a few aces you can pull off your sleeve.
One of them is to use Dancer as a spur-of-the-moment bare bone web server:
$ dancer -a proxy $ cd proxy $ rm -fr public/ && ln -s /path/to/share public $ ./bin/app.pl -p 8086
With that, we now have a single-threaded web server listening on port 8086 serving
the files of /path/to/share
.
If you need it to be more beefy, as in act like a real web server and deal with concurent requests, just plack it up:
$ plackup bin/app.pl -p 8086
Meanwhile, in the Comment Section…
noah has been suggesting a Python variant using its core module simpleHTTPServer:
$ python -mSimpleHTTPServer
Aristotle, meanwhile, has summoned the power of Plack::App::Directory, which has the added bonus of generating auto-indexes:
$ plackup -MPlack::App::Directory -e’Plack::App::Directory->to_app’
That was going straight into my list of aliases as
alias instaweb="plackup -MPlack::App::Directory -e'Plack::App::Directory->to_app'"
but Pedro Melo chimed in and pointed
our attention to App::HTTPThis, which uses Plack::App::Directory
under the hood and provides the utility ’http_this
’. With it, sharing a directory via http
is as simple as running
$ cd /path/to/dir/we/wanna/share $ http_this
Can things possibly get any sweeter?