[Dancer-users] Global app-wide "prefix" settings

Assaf Gordon gordon at cshl.edu
Wed Sep 21 17:34:40 CEST 2011


sawyer x wrote, On 09/21/2011 02:40 AM:
> On Wed, Sep 14, 2011 at 8:13 PM, Assaf Gordon <gordon at cshl.edu <mailto:gordon at cshl.edu>> wrote:
> >    Is there a way to specify a application-wide "prefix" settings ?
> >    The "prefix" keyword affects only the routes subroutines, but not the static/public files.
> 
> I think you're referring to "appdir". It can be set from a config file and/or from your application.

I don't think so (unless I'm misreading the meaning of "appdir").
It's my impression that "appdir" refers to physical directories, where the application will find the relevant resource files.

What I'm looking for is a way to globally add a *URL* prefix to the entire application.

<begin long explanation>

Others have mentioned deploying multiple dancer applications on the same server.
It seems the most common solution is to have a virtual host, and the root directory of the virtual host goes to each individual dancer app.

So that:
  http://app1.cshl.edu/  => Application 1
  http://app2.cshl.edu/  => Application 2
  http://app3.cshl.edu/  => Application 3

Even if they are all virtual hosts running on the same physical server.

That's OK, but I'm looking for a way do have multiple Dancers run from the same host, but with different URL prefixes:

  http://server.cshl.edu/app1/ => application 1
  http://server.cshl.edu/app2/ => application 2
  http://server.cshl.edu/app3/ => application 3

When it comes to routes, that is easily doable with the "prefix" keyword.

But the "prefix" keyword doesn't take care of static files (javascripts/images/css) - those will still be rendered (due to "request.uri_base" in the template) as
  http://server.cshl.edu/css/style.css
instead of 
  http://server.cshl.edu/app1/css/style.css (per dancer application).

Obviously, one can edit every template file to make sure the URL has the application's prefix.
But it's an ugly hard-coded solution, and requires synchronization between the perl code's "prefix" and the template's hardocded URLs.


I want an application-wide "prefix" setting (in the config file, or similar), that would affect every part of the application.

<begin long example>

-1-
If I create a new dancer application, and add the following route:

 get '/mydata' => sub {
	(whatever)
 }

And my server is "http://server.cshl.edu", then by default, the application's URLs would be:
  http://server.cshl.edu/        => root route
  http://server.cshl.edu/mydata  => my code
  http://server.cshl.edu/images/ => static images
  http://server.cshl.edu/css/    => static CSS
  http://server.cshl.edu/javascript/ => static javascripts


-2-
If I add a "prefix => "/app1" " statement in my code, the URLs become:
  http://server.cshl.edu/app1         => root route
  http://server.cshl.edu/app1/mydata  => my code
  http://server.cshl.edu/images/      => static images
  http://server.cshl.edu/css/         => static CSS
  http://server.cshl.edu/javascript/  => static javascripts

The URL for the route changed, but not for the static files.

-3-
What I'm looking for is a way to specify that "/app1" should now be a prefix for everything, including static files.
and preferably, be able to do it from the configuration file - this would allow me to change the URL of deployed applications without changing a single line of code.


Thanks for reading so far,
 -gordon


More information about the Dancer-users mailing list