Created
February 4, 2019 14:59
-
-
Save marcusramberg/a060ec04325aa4467f08b6c2dd72bd97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Mojolicious::Lite; | |
_setup_status_page(app); | |
get '/' => sub { | |
my $c = shift; | |
$c->render_later; | |
$c->ua->get('/internal', sub { | |
my ($ua,$tx)=@_; | |
$c->render(text=>$tx->res->json('/res')); | |
}); | |
}; | |
get '/internal' => sub { | |
my $c = shift; | |
$c->render( json=> {res=>'2'} ); | |
}; | |
sub _setup_status_page { | |
# Secure access to the server status ui with Basic authentication | |
my $self = shift; | |
my $under = $self->routes->under('/status' =>sub { | |
my $c = shift; | |
return 1 if $c->req->url->to_abs->userinfo eq 'admin:password'; | |
$c->res->headers->www_authenticate('Basic'); | |
$c->render(text => 'Authentication required!', status => 401); | |
return undef; | |
}); | |
$self->plugin('Status', {route => $under }); | |
} | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment