Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


In reply to Mojolicious, apache reverse proxy by slatibart

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found