Simplest way of serving local files over HTTP?
I've always admired Python's way of serving local files by simply doing:
$ python -m SimpleHTTPServer Serving HTTP on 0.0.0.0 port 8000 ...
And I've been wondering if there's a way to achieve the same in Perl without requiring lots of dependencies from CPAN. This morning I just came out with this:
$ perl -Mojo -E 'a->static->paths(["."]);a->start' daemon Server available at http://127.0.0.1:3000
It shows the file content, though it doesn't show the directory listing.
Is there any simpler way?
According to this PerlMonks node you can use "http_this", which is this code:
Though even that doesn't start with Perl. The web has also yielded
I've been using
http_this
for a long time. It's easy to install if you're used to CPAN and just a simple command without mandatory arguments. Much better than any Perl or Python code to remember and type in each time.You can check out my own mccs. You can serve cwd with just:
But no directory listing (at this time)Thanks for the comments, I like
Plack::App::Directory
behaviour better than my own suggestion because it shows the access logs. It has been suggested twice on Twitter, so it seems to be fairly known. Too bad it's not part of core Perl or default Perl modules installed by the OS distros.Is it worth mentioning X-Sendfile ? It is used if your code has decided to serve a static file. There are several ways of using X-Sendfile from Perl.
http://search.cpan.org/dist/Catalyst-Plugin-XSendFile/lib/Catalyst/Plugin/XSendFile.pm
http://www.perlmonks.org/?node_id=1000255
Basically you add a response header then Apache or lighty serves the file for you. That is much more efficient than serving it from Perl.
Cheers -- Rick