Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Webserver Oneliner

by alpha-lemming (Novice)
on Oct 15, 2010 at 09:14 UTC ( #865436=perlquestion: print w/ replies, xml ) Need Help??
alpha-lemming has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm looking for the quickest, shortest way to start an HTTP server that serves the contents of the current directory. Shortest code gets a shiny star!

Comment on Webserver Oneliner
Re: Webserver Oneliner
by marto (Chancellor) on Oct 15, 2010 at 09:26 UTC

    Why does it have to be a 'Oneliner'? Do you have an existing web server or are you looking for something like HTTP::Server::Simple?

Re: Webserver Oneliner
by moritz (Cardinal) on Oct 15, 2010 at 09:33 UTC
      The above link is helpful, thanks. Should have searched first :/
        The below code will trigger some ideas.

        HTTP::Daemon - http://search.cpan.org/~gaas/libwww-perl-5.837/lib/HTTP/Daemon.pm
        #!/usr/bin/perl use HTTP::Daemon; use HTTP::Status; my $d = HTTP::Daemon->new( LocalAddr => 'hostname', LocalPort => 8090, ); #$d = HTTP::Daemon->new || die; print "Please contact me at: <URL:", $d->url, ">\n"; while (my $c = $d->accept) { while (my $r = $c->get_request) { if ($r->method eq 'GET') { my $pathvar = $r->uri->path(); @exact_path = split("/",$pathvar); $c->send_file_response(@exact_path[1]); } else { $c->send_error(RC_FORBIDDEN) } } $c->close; undef($c); }
        Regards,
        Vivek
Re: Webserver Oneliner
by bduggan (Pilgrim) on Oct 15, 2010 at 11:54 UTC
Re: Webserver Oneliner
by Ea (Friar) on Jan 17, 2013 at 17:19 UTC
    Two years late, but I'll have that shiny star!

    http_this

    Written 3 months earlier than the question, it's just a wrapper around the Plack::App::Directory which was suggested earlier, but it's simpler, like the python command in a book on D3 that sent me looking for the perl equivalent of python -m SimpleHTTPServer

    perl -e 'print qq(Just another Perl Hacker\n)' # where's the irony switch?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://865436]
Approved by AnomalousMonk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (15)
As of 2014-09-02 13:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (22 votes), past polls