App-PerinciUtils

 view release on metacpan or  search on metacpan

script/peri-htserve  view on Meta::CPAN


    my @argv;
    push @argv, "-s", $server;
    my @root_urls; # for hint
    if ($server eq 'Starman') {
        for (qw/host port/) {
            push @argv, "--$_", $args{"starman_$_"} if $args{"starman_$_"};
        }

        my $host = $args{starman_host} // 'localhost';
        my $port = $args{starman_port} // 8080;
        push @root_urls, "http://$host:$port/";
    } else {
        if (!$args{gepok_http_ports} &&
                !$args{gepok_https_ports} &&
                    !$args{gepok_unix_sockets}) {
            $args{gepok_http_ports} = "*:5000";
        }
        for (qw/http_port https_ports unix_sockets
                ssl_key_file ssl_cert_file start_servers/) {
            push @argv, "--$_", $args{"gepok_$_"} if defined $args{"gepok_$_"};
        }

        my ($host, $port) = @_;
        if ($args{gepok_http_ports}) {
            if ($args{gepok_http_ports} =~ /(.+?):(\d+)/) {
                $host = $1; $host = 'localhost' if $host eq '*';
                $port = $2;
            } elsif ($args{gepok_http_ports} =~ /(\d+)/) {
                $host = 'localhost';
                $port = $1;
            }
            push @root_urls, "http://$host:$port/";
        }
        if ($args{gepok_https_ports}) {
            if ($args{gepok_https_ports} =~ /(.+?):(\d+)/) {
                $host = $1; $host = 'localhost' if $host eq '*';
                $port = $2;
            } elsif ($args{gepok_https_ports} =~ /(\d+)/) {
                $host = 'localhost';
                $port = $1;
            }
            push @root_urls, "https://$host:$port/";
        }
        if ($args{gepok_unix_sockets}) {
            if ($args{gepok_unix_sockets} =~ /(.+?)(?:,|\z)/) {
                push @root_urls, "http:$1//";
            }
        }
    }

    # display hint for user
    if (@root_urls) {
        my @ep_urls; # api endpoints
        for my $root_url (@root_urls) {
            for my $pkg (@pkgs) {
                my $pkgp = $pkg; $pkgp =~ s!::!/!g;
                push @ep_urls, $root_url . "api/$pkgp/";
            }
        }
        say "Try accessing one of the following URLs with curl/riap/etc:";
        print map { "- $_\n" } @ep_urls;
        say "";
    }

    push @argv, "-D" if $args{daemonize};
    my $runner = Plack::Runner->new;
    $runner->parse_options(@argv);
    $runner->run($app);

    # never reached though
    [200, "OK"];
}

Perinci::CmdLine::Any->new(url => '/main/serve')->run;

# ABSTRACT: Serve Perl modules over HTTP(S) using Riap::HTTP protocol
# PODNAME: peri-htserve

__END__

=pod

=encoding UTF-8

=head1 NAME

peri-htserve - Serve Perl modules over HTTP(S) using Riap::HTTP protocol

=head1 VERSION

This document describes version 0.112 of peri-htserve (from Perl distribution App-PerinciUtils), released on 2019-01-20.

=head1 SYNOPSIS

 # serve modules over HTTP, using default options (HTTP port 5000)
 $ peri-htserve Foo::Bar Baz::*

 # you can now do
 $ curl 'http://localhost:5000/api/Baz/SubMod/func1?arg1=1&arg2=2'
 [200,"OK",{"The":"result","...":"..."}]

 # or use the Perl client
 $ perl -MPerinci::Access -e'
     my $pa = Perinci::Access->new;
     my $res = $pa->request(call=>"http://localhost:5000/api/Foo/Bar/func2");'


 ### some other peri-htserve options:

 # change ports/etc (see http_ports, https_ports, and unix_sockets in Gepok doc)
 $ peri-htserve --http-ports "localhost:5000,*:80" ...

 # see all available options
 $ peri-htserve --help

=head1 DESCRIPTION

For now, please see source code for more details (or --help).

=head1 QUICK TIPS

=head2 Complex argument



( run in 0.331 second using v1.01-cache-2.11-cpan-a1f116cd669 )