View on
Flavio Poletti > Dancer-Middleware-Rebase-0.8.0 > Dancer::Middleware::Rebase



Annotate this POD

View/Report Bugs
Module Version: 0.8.0   Source  


Dancer::Middleware::Rebase - a Plack middleware to be used for Dancer


version 0.8.0


This is a Plack::Middleware specifically geared to the Dancer framework. The goal is to let you rebase your application easily, i.e. let you move your application that usually lives in into or even

This can be particularly useful in a reverse-proxy deployment, where the application is called by the proxy HTTP server and thus lives in a different namespace with respect to the one available to the end user.

Suppose for example that you have a reverse-proxy deployment, where the end user calls route /homepage in your application using the URI If you are using Apache with the following configuration:

   ProxyPass        /app/ http://internal:3000/
   ProxyPassReverse /app/ http://internal:3000/

then the route in your application will be called as http://internal:3000/homepage. This leads to two problems:

You might think that you can address the latter problem with a proper Apache configuration:

   ProxyPass        /app/ http://internal:3000/app/
   ProxyPassReverse /app/ http://internal:3000/app/

but with this configuration you receive a request towards http://internal:3000/app/homepage, which is not going to work smoothly for different reasons:

Dancer::Middleware::Rebase addresses all these problems at the same time. You can set a base URI that will be propagated in the $env passed to your application. In particular, it will set all the proper variables that are then used by Dancer::Request methods base() and uri_for() in order to establish the URI where all stuff can be referred.

In case you like keeping the prefix part in the Apache configuration, anyway, you still have the problem of stripping it before giving it to the application. In this case, you can set a strip parameter to eliminate the prefix from the PATH_INFO component of $env.


This module is a Plack::Middleware, so you have to configure it inside plack_middlewares like this:

         - "+Dancer::Middleware::Rebase"
         - base
         - ""
         - strip
         - 1

Please note that you have to put a plus sign before the module name, otherwise Plack will think that it is a name to be referred to the Plack::Middleware namespace.

You can set the following options:


the URI that has to be set as the base one. This will be what you eventually get when you call request.base in your code and in your templates, and it is also used by uri_for.


either a true value or a string that starts with /. In the first case, the path portion of the base URI will be used as a prefix to be stripped from PATH_INFO, otherwise the specified string is used. You should only need the first approach, anyway.


Flavio Poletti <>


Copyright (C) 2011 by Flavio Poletti <>.

This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.

syntax highlighting: