Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: eede14b552
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 52 lines (46 sloc) 1.104 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
use HTTP::Daemon;
use Tags;

defined @*ARGS[0] && @*ARGS[0] eq '--request' ?? request() !! daemon();

sub request($c) {
    my $r = $c.get_request();
    if $r.req_method eq 'GET' {
        given $r.url.path {
            when '/' { root_dir( $c, $r ); }
            when / ^ \/pub\/ $ / { pub_dir( $c, $r ); }
        }
    }
    else {
        $c.send_error('RC_FORBIDDEN');
    }
}

sub root_dir($c, $r) {
    $c.send_response: show {
        html {
            head {
                title { "hi dood" }
            };
            body {
                h1 { 'wtf dood?!?!?!' }
                a :href</pub/>, { 'some stuff' }
            }
        }
    }
}

sub pub_dir($c, $r) {
    $c.send_response: show {
        html {
            head {
                title { "public filezzzzzzzz" }
            };
            body {
                p { 'hi dood' }
                a :href</>, { 'main page' }
            }
        }
    }
}

sub daemon {
    my HTTP::Daemon $d .= new( :host('127.0.0.1'), :port(2080) );
    say "Browse this Perl 6 web server at {$d.url}";
    $d.daemon();
}
Something went wrong with that request. Please try again.