Last active
May 22, 2017 19:15
-
-
Save aferreira/7767f71ce49425465bd518aafa2f0051 to your computer and use it in GitHub Desktop.
My take on "How to write checkip.amazonaws.com service with Mojo?"
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
| # Take a look at https://github.com/aferreira/acme-docker-checkip | |
| package CheckIP; | |
| use Mojo::Base 'Mojo'; | |
| use Mojolicious::Commands; | |
| use Scalar::Util; | |
| has commands => sub { | |
| my $commands = Mojolicious::Commands->new( app => shift ); | |
| Scalar::Util::weaken $commands->{app}; | |
| return $commands; | |
| }; | |
| sub handler { | |
| my ( $self, $tx ) = @_; | |
| my $ip = $tx->remote_address; | |
| # Response | |
| $tx->res->code(200); | |
| $tx->res->headers->content_type('text/plain'); | |
| $tx->res->body("$ip\n"); | |
| # Resume transaction | |
| $tx->resume; | |
| } | |
| sub start { | |
| my $self = shift; | |
| return $self->commands->run( @_ ? @_ : @ARGV ); | |
| } | |
| 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment