Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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!

Replies are listed 'Best First'.
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 -
        #!/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); }
Re: Webserver Oneliner
by marto (Bishop) 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 bduggan (Pilgrim) on Oct 15, 2010 at 11:54 UTC
Re: Webserver Oneliner
by Ea (Hermit) on Jan 17, 2013 at 17:19 UTC
    Two years late, but I'll have that shiny star!


    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?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2016-10-22 05:56 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (292 votes). Check out past polls.