use URI::QueryParam;
use Moose::Util::TypeConstraints;
use Plack::Loader;
+use Plack::Middleware::Conditional;
+use Plack::Middleware::ReverseProxy;
use namespace::clean -except => 'meta';
sub run {
my ($self, $app, @args) = @_;
- Carp::cluck("Run");
# FIXME - Do something sensible with the options we're passed
$self->_run_psgi_app($self->_build_psgi_app($app, @args), @args);
}
sub _build_psgi_app {
my ($self, $app, @args) = @_;
- return sub {
+
+ my $psgi_app = sub {
my ($env) = @_;
return sub {
$app->handle_request(env => $env);
};
};
+
+ $psgi_app = Plack::Middleware::Conditional->wrap(
+ $psgi_app,
+ condition => sub {
+ my ($env) = @_;
+ return if $app->config->{ignore_frontend_proxy};
+ return $env->{REMOTE_ADDR} eq '127.0.0.1' || $app->config->{using_frontend_proxy};
+ },
+ builder => sub { Plack::Middleware::ReverseProxy->wrap($_[0]) },
+ );
+
+ return $psgi_app;
}
sub _run_psgi_app {
- my ($self, $psgi_app, @args);
+ my ($self, $psgi_app, @args) = @_;
# FIXME - Need to be able to specify engine and pass options..
- Plack::Loader->auto()->run($psgi_app);
+ Plack::Loader->auto(port => $args[0])->run($psgi_app);
}
=head2 $self->write($c, $buffer)