Replies: 2 comments 8 replies
-
You need to prevent |
Beta Was this translation helpful? Give feedback.
4 replies
-
Perhaps something like this? use Mojolicious::Lite -signatures, -async_await;
helper my_ua => sub {
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new->inactivity_timeout(15)->max_redirects(5);
$ua
};
any '/' => async sub ($c) {
my $url = Mojo::URL->new('https://httpbin.org/json');
$c->render_later();
my $results = await Mojo::Promise->all_settled( $c->my_ua->get_p( $url ) );
if ($results->{status} eq "fulfilled") {
my $tx = $results->{value}[0];
my $json = $tx->res->json;
$c->render(json => $json);
}
else {
my $reason = $results->{reason}[0];
$c->render(json => {reason => $reason});
}
};
app->start; Also, if you're proxying requests consider the |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This has been annoying me for a while now, and it bugs me that it is listed in the FAQ, but with no explanation on how to solve it.
Say I have controller that is suppose to fetch a page online, get some info and return some JSON. Why does this not work (I replaced the return statements with
I keep getting "Premature connection close". I get that something runs out of scope. But when what exactly is the paradigm we should use for something like this?
Beta Was this translation helpful? Give feedback.
All reactions