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

Brian E. Lozier brian at massassi.com
Wed Sep 28 22:14:29 CEST 2011


On Wed, Sep 28, 2011 at 1:07 PM, Assaf Gordon <gordon at cshl.edu> wrote:

> sawyer x wrote, On 09/28/2011 03:33 PM:
> > On Wed, Sep 28, 2011 at 9:22 PM, Assaf Gordon <gordon at cshl.edu <mailto:
> gordon at cshl.edu>> wrote:
> >
> >     I understand the apache configuration part, but not the dancer part:
> >
> >     In my Dancer/Template-Toolkit file (e.g. "views/layout/main.tt <
> http://main.tt>"), I'm still using:
> >       <img src="[% request.uri_base %]/images/pic.jpg"/>
> >     and
> >       <link rel="stylesheet" href="[% request.uri_base %]/css/style.css"
> />
> >
> >     So the link (inside the generated HTML that the user will receive)
> will contain:
> >      http://server.cshl.edu/images/pic.jpg
> >     and
> >      http://server.cshl.edu/css/style.css
> >
> >
> > Indeed that's what the users will get. Then they have to run another
> request to the server to retrieve it, and that's when they hit the Alias
> rule which tells the apache "they're asking for /images/ but they actually
> want /app/images".
>
> I must be missing something big, because I just don't get it :)
>
> 1. If the user gets <src img="http://server.cshl.edu/images/pic.jpg"> and
> then retrieves it,
> an alias rule "Alias /app1/images /path/to/app1/public/images" (as
> suggested by Pedro Melo) will *not* catch it - unless I don't understand the
> meaning of Apache's "Alias".
>
> 2. If I have two dancer applications, and both generate URLS of "
> http://server.cshl.edu/images/pic.jpg" - how is it possible for apache to
> tell if this image belongs to the first application or the second ?
>
>
> Perhaps I'm not explaining myself well.
> I'll try to ask it in a different way:
>
> Has anyone been able to deploy a Dancer application *not* under the
> server's root URL,
> without changing code/templates in the Dancer application itself ?
>
> That is:
> 1. create default dancer application.
>   the index route's URL is "/"
>   the images URL is "/images/*"
>   the CSS URL is "/css/*"
>
> 2. SOME CONFIGURATION in Apache ??
>
> 3. The root URL of the entire application is now "/gordon/":
>  the index route's URL is "/gordon/"
>  the images URL is "/gordon/images/*"
>  the CSS URL is "/gordon/css/*"
>
> What should I do in step 2 ?
>

The only thing I can think of is to rewrite the html on the way out such
that all calls to /images/ get the prefix.  The problem is that all your
templates are hard coding a path to a resource on the server.  You're
telling the browser what resource to request and you're giving it an
"absolute" path.  You could also give them "relative" paths such as:

<img src="images/foo.png">

Which will work fine as long as you don't have any routes that are deeper.

Why don't you just have a configuration parameter in your config file that
says "path" and then use that instead of "[% request.uri_base %]"?  I don't
quite get why you're using uri_base anyway.  All you have to do is say:

<img src="/images/foo.png">

and it will default to pulling from the same server the page was served
from.  You could mod all your templates to say something like:

<img src="[% images_path %]/foo.png">

And then control it via config.

I agree that this isn't something Dancer should strive to support, it's
really an odd request (hard coding resource URLs and then expecting the app
layer to rewrite outbound HTML or something).


>
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.backup-manager.org/pipermail/dancer-users/attachments/20110928/a907d964/attachment.htm>


More information about the Dancer-users mailing list