You might want to try http://p3rl.org/Mojolicious::Plugin::RequestBase
On Sunday, 18 December 2016 11:00:59 UTC, Martin Cernicka wrote: > > Hello, > > I am struggling with the deployment of a simple Mojolicious::Lite > application under Apache ReverseProxy with a relative path. The application > base URL looks like this: https://localhost/test. It works fine without > /test at the end. > > The generated URLs do look fine, but the routes never match. They do > match, however, if the path is entered twice, like > https://localhost/test/test/show_form. > > This is my setup on a Debian 8 Jessie: > > morbo running on http://localhost:3001, works fine when contacted > directly. > Application URL: https://localhost/test > > Apache configuration: > ProxyPreserveHost On > ProxyPass /test http://localhost:3001/ > ProxyPassReverse /test http://localhost:3001/ > RequestHeader set X-Forwarded-HTTPS "1" > > The application: > #!/usr/bin/env perl > use Mojolicious::Lite; > use Data::Dumper; > > hook before_dispatch => sub { > my $c = shift; > if ( $c->req->headers->header('X-Forwarded-Host') ) { > $c->req->url->base->scheme('https'); > $c->req->url->base->path('test'); > } > }; > > get '/' => sub { > my $c = shift; > $c->stash( debug => 'url:' . Dumper( $c->req->url ) ); > } => 'index'; > > get 'show_form' => 'menu'; > > get 'save_form' => sub { > my $c = shift; > $c->stash( input => $c->param('input') ); > } => 'show_saved'; > > app->start; > __DATA__ > > @@ index.html.ep > % layout 'default'; > <p><%= link_to('Form' => 'show_form') %>: leads nowhere > <br><a href="/test/test/show_form">Form > manual link</a>: this works under apache ReverseProxy, but obviously not > without > <p><%= link_to('Home' => '/') %> > <pre><%= stash 'debug' %></pre> > > @@ layouts/default.html.ep > <!DOCTYPE html> > <html> > <head><title><%= title %></title></head> > <body><%= content %></body> > </html> > > @@ menu.html.ep > % layout 'default'; > This is a test form > %= form_for save_form => (method => 'GET') => begin > <br>Desc <input type="text" name="input"> > <br><input type="submit" value="Save"> > % end > > @@ show_saved.html.ep > % layout 'default'; > You entered: desc="<%= stash 'input' %>". > <br>Return <%= link_to 'home' => '/' %>. > > > And the contents of $c->req->url, as displayed on the first page: > > url:$VAR1 = bless( { > 'path' => bless( { > 'charset' => 'UTF-8', > 'path' => '/' > }, 'Mojo::Path' ), > 'query' => bless( { > 'pairs' => [] > }, 'Mojo::Parameters' ), > 'base' => bless( { > 'scheme' => 'https', > 'path' => bless( { > 'charset' => 'UTF-8', > 'leading_slash' => '', > 'trailing_slash' => '', > 'parts' => [ > 'test' > ] > }, 'Mojo::Path' ), > 'host' => '127.0.0.1' > }, 'Mojo::URL' ) > }, 'Mojo::URL' ); > > > As far as I understood the Cookbook#Rewriting > <http://mojolicious.org/perldoc/Mojolicious/Guides/Cookbook#Rewriting> > (not very far, it seems), moving the req->url->path->leading_slash(0) to > req->url->base->path->trailing_slash(1) is the way to go. But it is empty > in my case and doesn't help. Adding a trailing slash to the URL makes the > path appear twice in the links (https://localhost/test/test/show_form) > and it matches nicely, e.g. the form appears after clicking on the link. > But the form_for URL is correct/wrong again (test/save_form, won't match > the route 'save_form'). > > Yet elsewhere > <https://groups.google.com/forum/#!msg/mojolicious/AA4lHwdIyZc/XJBZQ2nrjRUJ> > Sebastian suggests to move a chunk from path->parts to base->path->parts. > Empty here as well, no matter if the URL contains a trailing slash or not. > > I tried hypnotoad instead of morbo, production instead of development, > adding slashes here and there, but still can't seem to figure it out. > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
