Created
June 19, 2015 18:49
-
-
Save diegok/67ed2c970cd6d0dcd8f2 to your computer and use it in GitHub Desktop.
Mojolicious proxy
This file contains 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; | |
my $backend = Mojo::URL->new('https://soysuper.com'); | |
any '/' => \&proxy; | |
any '/*path' => \&proxy; | |
sub proxy { | |
my $c = shift; | |
my $req = $c->req->clone; | |
my $url = $backend->clone; | |
$url->path($c->stash('path')) if $c->stash('path'); | |
$req->url($url); | |
$req->headers->header(host => $url->host); | |
$c->ua->start(Mojo::Transaction::HTTP->new(req => $req) => sub { | |
$c->tx->res(pop->res); | |
$c->rendered; | |
}); | |
}; | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment