Skip to content

Instantly share code, notes, and snippets.

@diegok
Created June 19, 2015 18:49
Show Gist options
  • Save diegok/67ed2c970cd6d0dcd8f2 to your computer and use it in GitHub Desktop.
Save diegok/67ed2c970cd6d0dcd8f2 to your computer and use it in GitHub Desktop.
Mojolicious proxy
#!/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