in reply to Re: Dancer2 App Deployment through Apache Proxy
in thread Dancer2 App Deployment through Apache Proxy
package Plack::Middleware::Proxy; use warnings; use strict; use parent 'Plack::Middleware'; use Plack::Util::Accessor qw( prefix scheme ); sub call { my ($self, $env) = @_; if ($env->{REMOTE_ADDR} ne '127.0.0.1') { $env->{SCRIPT_NAME} = $self->prefix; $env->{HTTP_X_FORWARDED_PROTO} = $self->scheme; } my $res = $self->app->($env); return Plack::Util::response_cb($res, sub { my $res = shift; if ($res->[0] == 302) { my %header = @{ $res->[1] }; my $prefix = $self->prefix; $header{Location} =~ s{^\Q$prefix/}{/$prefix/}; @{ $res->[1] } = %header; } return }); return $res } __PACKAGE__
It sovles several problems at once:
I use it like this:
use Plack::Builder; builder { enable 'Plack::Middleware::Proxy', prefix => 'prefix', scheme => ' +https'; 'MyApp'->to_app; };
So, in the end, I also need to have the prefix in the code, but at least as a parameter to middleware, which seems much nicer.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Dancer2 App Deployment through Apache Proxy
by NERDVANA (Priest) on May 21, 2025 at 14:25 UTC |