Skip to content

Commit

Permalink
better rewriting recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 8, 2013
1 parent 22aa21d commit 268dd3e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -252,16 +252,19 @@ you can use a C<before_dispatch> hook to rewrite incoming requests.
});

Since reverse proxies generally don't pass along information about path
prefixes your application might be deployed under, rewriting the base URL of
prefixes your application might be deployed under, rewriting the base path of
incoming requests is also quite common.

# Change base URL and remove leading slash from path in production mode
# Move first part and slash from path to base path in production mode
app->hook(before_dispatch => sub {
my $self = shift;
$self->req->url->base(Mojo::URL->new('http://example.com/myapp/'));
$self->req->url->path->leading_slash(0);
push @{$self->req->url->base->path->trailing_slash(1)},
shift @{$self->req->url->path->leading_slash(0)};
}) if app->mode eq 'production';

L<Mojo::URL> objects are very easy to manipulate, just make sure that the URL
is always relative to the base URL.

=head2 Application embedding

From time to time you might want to reuse parts of L<Mojolicious> applications
Expand Down

0 comments on commit 268dd3e

Please sign in to comment.