http://qs1969.pair.com?node_id=11106378

slatibart has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have apache running and need to run a mojolicious app under the path /rules

This is the apache config part

ProxyRequests Off ProxyPreserveHost On ProxyPass /rules http://localhost:3000/ keepalive=On ProxyPassReverse /rules http://localhost:3000/ RequestHeader set X-Forwarded-HTTPS "0"
Very simply mojolicious script with a route to / and a route to /user
app->hook(before_dispatch => sub { my ( $c ) = @_; my $url = $c->req->url; my $base = $url->base;# push @{ $base->path }, 'rules'; $base->path->trailing_slash(1); $url->path->leading_slash(0); }); get '/' => sub { my $self = shift; my $host = $self->tx->remote_address; my $content = "Host: $host"; $self->stash(content=>$content); $self->render('index'); }; get '/user' => sub { my $self = shift; my $host = $self->tx->remote_address; my $content = "Host: $host"; $self->stash(content=>$content); $self->render('index'); }; app->start; __DATA__ @@ index.html.ep % layout 'default'; <%== $content %> @@ layouts/default.html.ep <!DOCTYPE html> <html lang="en"> <head> <title>Test</title> </head> <body> %= button_to Home => '/' %= button_to User => '/user' %= link_to Home => '/' %= link_to User => 'user' %= content </body> </html>
Generated html looks good.
<!DOCTYPE html> <html lang="en"> <head> <title>Test</title> </head> <body> <form action="/rules"><input type="submit" value="Home"></form> <form action="/rules/user"><input type="submit" value="User"></form> <a href="/rules">Home</a> <a href="/rules/user">User</a> Host: 127.0.0.1 </body> </html>
Using the home button / links works but for route /user mojolicous throws an error.

"None of these routes could generate a response for your GET request for //user, maybe you need to add a new one?"

Where is that extra slash coming from and how to get rid of that ?

Bonus question. If I add another layer   push @{ $base->path }, 'all/rules'; all slashes are transformed.

<form action="/all%2Frules"><input type="submit" value="Home"></form> <form action="/all%2Frules/user"><input type="submit" value="User"></f +orm> <a href="/all%2Frules">Home</a> <a href="/all%2Frules/user">User</a>
Any idea why ?

Thanks for your help.