Question

Edited the question. I have this simple Plack app.psgi:

my $app = sub {
    my $env = shift;
    return [
        200,
        ['Content-Type' => 'text/html'],
        [ "<html><head><title>x</title></head><body><pre>Path info: $env->{PATH_INFO}</pre></body></html>"],
    ];
};

use Plack::Builder;
builder {
    enable 'Debug';
    $app;
};

running it with a simple plackup.

When from the local machine accessing: http://localhost:5000/some/path, it prints: Path info: /some/path and got a nice working Plack debug panel.

Now, I have apache:80 configured as following:

ProxyPass        /myapp/ http://127.0.0.1:5000/
ProxyPassReverse /myapp/ http://127.0.0.1:5000/

So, all requests what comes to: http://SITE/myapp/ is proxied to the above Plack app. So, when trying access it via

http://SITE/myapp/some/path

the browser again, correctly prints:

Path info: /some/path

But the "Plack::Middleware/Debug" doesn't works, because he sends the next URLs to the browser:

jquery.js -> /debug_toolbar/jquery.js
toolbar.min.js -> /debug_toolbar/toolbar.min.js

and of course, theyre doesn't exists. (They should be /myapp/debug_toolbar/....)

So the question is:

  • WHAT I NEED TO DO - how to change the above app.psgi to get an working app?
  • I need somewhat change all outgoing URLs with a prefix /myapp/
Was it helpful?

Solution

update: I imagine all you need is to add the following

enable "ReverseProxy";     ##  Plack::Middleware::ReverseProxy 
enable "ReverseProxyPath"; ##  Plack::Middleware::ReverseProxyPath 

update: You might also need to edit your apache httpd conf to add nocanon to proxypass...

below*is*original**response

It isn't hardcoded, see for yourself (I had to)

https://github.com/plack/Plack/wiki/How-to-detect-reverse-proxy-and-SSL-frontend http://p3rl.org/Plack::Middleware::ReverseProxy http://advent.plackperl.org/2009/12/day-12-maps-multiple-apps-with-mount-and-urlmap.html

#!/usr/bin/perl --
#~ plack-debug-mounted.pl
#~ 2013-10-17-02:59:26
#~ 
## perltidy -olq  -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr -ce -nibc -i=4 -pt=0   "-nsak=*"
#!/usr/bin/perl --
use CGI();
use Data::Dump qw/ dd pp /;
use Path::Tiny qw/ path /;
use Plack::Builder;
use Plack::Runner;

my $selfsourceapp = sub {
    return [
        '200',
        [ 'Content-Type' => 'text/plain', ],
        [ path( __FILE__ )->slurp_raw ],
    ];
};
my $dumperapp = sub {
    my $q = CGI->new( $_[0] );
    return [
        '200', [
            'Content-Type'   => 'text/html',
            'Content-Length' => '2',
        ], [
            $q->start_html( -title => 'dumpenv.psgi' ),
            $q->h1( $_[0]->{SCRIPT_NAME} ),
            $q->Dump, $q->end_html,
        ],
    ];
};

my $indexapp = sub {
    return [
        '200',
        [ 'Content-Type' => 'text/html', ],
        [
            q{<doctype html>
<html lang="en-US" charset="UTF-8">
<title> Plack perlology </title>
<body>
<p> A Plack::Middleware::Debug free zone
<br> <a href="/"> this </a>
<br> <a href="/dumpenv"> dupenv </a>
<br> <a href="/selfsrc"> selfsrc </a>
<p> Get <c>Plack::Middleware::Debug</c> <b> ed </b>
<br> <a href="/debugged/"> /debugged/ this </a>
<br> <a href="/debugged/dumpenv"> /debugged/dupenv </a>
<br> <a href="/debugged/selfsrc"> /debugged/selfsrc </a>
<p> Come get some
<br> <a href="/debugged/debug_toolbar/toolbar.min.css">
/debugged/debug_toolbar/toolbar.min.css
</a>
<br> <a href="/debugged/debug_toolbar/toolbar.min.js">
/debugged/debug_toolbar/toolbar.min.js
</a>
<p> Cant get this
<br> <a href="/debug_toolbar/toolbar.min.css">
/debug_toolbar/toolbar.min.css
</a>
<br> <a href="/toolbar.min.css">
/toolbar.min.css
</a>

</body><!-- before this Plack::Middleware::Debug inserts, viewsource!! -->
}
        ],
    ];
};

my $finalapp = builder {
    mount '/debugged' => builder {
        enable 'Debug', panels => [
            qw/
              Timer
              Response
              Environment
              Session
              Parameters
              /
        ];
        mount "/dumpenv" => $dumperapp;
        mount "/selfsrc" => $selfsourceapp;
        mount "/"        => $indexapp;
    };

    mount "/dumpenv" => $dumperapp;
    mount "/selfsrc" => $selfsourceapp;
    mount "/"        => $indexapp;
};

my $runner = Plack::Runner->new;
$runner->parse_options( qw' --host 127.0.0.1 --port 80 ' );
$runner->run( $finalapp );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top