Mailing List Archive

Please help to figure out with URL's
Hello to all,
I'm very beginner in Catalyst and now I've faced up with the problem: on my
dev sever (script/myapp_server.pl) I've got urls to static files like, for
example 0.0.0.0/image.png, instead of localhost:3000/image.png. (in
template it looks like <img src="/image.png" />
So, I can't load any static file in my dev-server. Please, help me to
figure out what's going.
And yes, uri_for('/image.png') works fine, but, may be, there is another
way to do it?

Thanks for youre help.
Re: Please help to figure out with URL's [ In reply to ]
Hi,

tl;dr - Use c.uri_for() everything, including statics.

I can't say why your links are 0.0.0.0/image.png without looking at the
full source of your page. I think your browser is doing this, maybe
with some (bad) hints.

However... c.uri_for('/image.png') is the right way to do it. It will
make sure the correct hostname, port, and path prefix for your
application are used, and it makes your app relocatable -- meaning you
won't have to change all of your static urls when your app's URL or root
path changes.

This is a typical use:

<link href="[% c.uri_for('/static/css/my_style.css') | html %]"
rel="stylesheet">

Cheers,
--Trevor

On 12/04/2014 11:23 AM, Александер Пономарёв wrote:
> Hello to all,
> I'm very beginner in Catalyst and now I've faced up with the problem: on
> my dev sever (script/myapp_server.pl <http://myapp_server.pl>) I've got
> urls to static files like, for example 0.0.0.0/image.png
> <http://0.0.0.0/image.png>, instead of localhost:3000/image.png. (in
> template it looks like <img src="/image.png" />
> So, I can't load any static file in my dev-server. Please, help me to
> figure out what's going.
> And yes, uri_for('/image.png') works fine, but, may be, there is another
> way to do it?
>
> Thanks for youre help.
>
>
> _______________________________________________
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Re: Please help to figure out with URL's [ In reply to ]
Yes, it comes from my browser, but I don't think it's normal, because I
didn't see it before in my mojolicious application.
Anyway, I think, there is the way to tweak an environment of the dev
server. Am I right? ;-)

2014-12-05 1:41 GMT+06:00 Trevor Leffler <tleffler@uw.edu>:

> Hi,
>
> tl;dr - Use c.uri_for() everything, including statics.
>
> I can't say why your links are 0.0.0.0/image.png without looking at the
> full source of your page. I think your browser is doing this, maybe with
> some (bad) hints.
>
> However... c.uri_for('/image.png') is the right way to do it. It will
> make sure the correct hostname, port, and path prefix for your application
> are used, and it makes your app relocatable -- meaning you won't have to
> change all of your static urls when your app's URL or root path changes.
>
> This is a typical use:
>
> <link href="[% c.uri_for('/static/css/my_style.css') | html %]"
> rel="stylesheet">
>
> Cheers,
> --Trevor
>
> On 12/04/2014 11:23 AM, Александер Пономарёв wrote:
>
>> Hello to all,
>> I'm very beginner in Catalyst and now I've faced up with the problem: on
>> my dev sever (script/myapp_server.pl <http://myapp_server.pl>) I've got
>> urls to static files like, for example 0.0.0.0/image.png
>> <http://0.0.0.0/image.png>, instead of localhost:3000/image.png. (in
>> template it looks like <img src="/image.png" />
>> So, I can't load any static file in my dev-server. Please, help me to
>> figure out what's going.
>> And yes, uri_for('/image.png') works fine, but, may be, there is another
>> way to do it?
>>
>> Thanks for youre help.
>>
>>
>> _______________________________________________
>> List: Catalyst@lists.scsys.co.uk
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: http://www.mail-archive.com/
>> catalyst@lists.scsys.co.uk/
>> Dev site: http://dev.catalyst.perl.org/
>>
>>
> _______________________________________________
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/
> catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
Re: Please help to figure out with URL's [ In reply to ]
I think you need to figure out what the problem is before knowing
whether (and what) you need to tweak. You might try creating a simple,
minimal page and template with just a link and see if it's still
happening. Something like...

<html>
<head><title>Test</title></head>

<body>
<p><a href="/static/images/catalyst_logo.png"><img
src="/static/images/catalyst_logo.png"></a></p>
</body>
</html>


--Trevor

On 12/04/2014 12:00 PM, Александер Пономарёв wrote:
> Yes, it comes from my browser, but I don't think it's normal, because I
> didn't see it before in my mojolicious application.
> Anyway, I think, there is the way to tweak an environment of the dev
> server. Am I right? ;-)
>
> 2014-12-05 1:41 GMT+06:00 Trevor Leffler <tleffler@uw.edu
> <mailto:tleffler@uw.edu>>:
>
> Hi,
>
> tl;dr - Use c.uri_for() everything, including statics.
>
> I can't say why your links are 0.0.0.0/image.png
> <http://0.0.0.0/image.png> without looking at the full source of
> your page. I think your browser is doing this, maybe with some
> (bad) hints.
>
> However... c.uri_for('/image.png') is the right way to do it. It
> will make sure the correct hostname, port, and path prefix for your
> application are used, and it makes your app relocatable -- meaning
> you won't have to change all of your static urls when your app's URL
> or root path changes.
>
> This is a typical use:
>
> <link href="[% c.uri_for('/static/css/my___style.css') | html %]"
> rel="stylesheet">
>
> Cheers,
> --Trevor
>
> On 12/04/2014 11:23 AM, Александер Пономарёв wrote:
>
> Hello to all,
> I'm very beginner in Catalyst and now I've faced up with the
> problem: on
> my dev sever (script/myapp_server.pl <http://myapp_server.pl>
> <http://myapp_server.pl>) I've got
> urls to static files like, for example 0.0.0.0/image.png
> <http://0.0.0.0/image.png>
> <http://0.0.0.0/image.png>, instead of localhost:3000/image.png. (in
> template it looks like <img src="/image.png" />
> So, I can't load any static file in my dev-server. Please, help
> me to
> figure out what's going.
> And yes, uri_for('/image.png') works fine, but, may be, there is
> another
> way to do it?
>
> Thanks for youre help.
>
>
> _________________________________________________
> List: Catalyst@lists.scsys.co.uk <mailto:Catalyst@lists.scsys.co.uk>
> Listinfo:
> http://lists.scsys.co.uk/cgi-__bin/mailman/listinfo/catalyst
> <http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst>
> Searchable archive:
> http://www.mail-archive.com/__catalyst@lists.scsys.co.uk/
> <http://www.mail-archive.com/catalyst@lists.scsys.co.uk/>
> Dev site: http://dev.catalyst.perl.org/
>
>
> _________________________________________________
> List: Catalyst@lists.scsys.co.uk <mailto:Catalyst@lists.scsys.co.uk>
> Listinfo:
> http://lists.scsys.co.uk/cgi-__bin/mailman/listinfo/catalyst
> <http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst>
> Searchable archive:
> http://www.mail-archive.com/__catalyst@lists.scsys.co.uk/
> <http://www.mail-archive.com/catalyst@lists.scsys.co.uk/>
> Dev site: http://dev.catalyst.perl.org/
>
>
>
>
> _______________________________________________
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Re: Please help to figure out with URL's [ In reply to ]
On Thu, Dec 4, 2014, at 12:41 PM, Trevor Leffler wrote:
> This is a typical use:
>
> <link href="[% c.uri_for('/static/css/my_style.css') | html %]" rel="stylesheet">

Assuming you're using Template Toolkit, you should use the "url" filter,
not the "html" filter:

<link href="[% c.uri_for('/static/css/my_style.css') | url %]"
rel="stylesheet">


Larry

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Re: Please help to figure out with URL's [ In reply to ]
On 4 December 2014 at 20:31, Larry Leszczynski <larryl@emailplus.org> wrote:

>
> On Thu, Dec 4, 2014, at 12:41 PM, Trevor Leffler wrote:
> > This is a typical use:
> >
> > <link href="[% c.uri_for('/static/css/my_style.css') | html %]"
> rel="stylesheet">
>
> Assuming you're using Template Toolkit, you should use the "url" filter,
> not the "html" filter:
>
> <link href="[% c.uri_for('/static/css/my_style.css') | url %]"
> rel="stylesheet">
>

afaik a url should be uri encoded when it's a url, and everything should be
html encoded when in html. the point being uri_for already uri_encodes the
url, and you should then html encode it when embedding it on the page, as
'&' is valid in a url, but not vaild in html

so <link href="[% c.uri_for('/static/css/my_style.css') | html %]"
rel="stylesheet"> would be the correct method


> Larry
>
> _______________________________________________
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
Re: Please help to figure out with URL's [ In reply to ]
* Larry Leszczynski <larryl@emailplus.org> [2014-12-04 21:35]:
> On Thu, Dec 4, 2014, at 12:41 PM, Trevor Leffler wrote:
> > This is a typical use:
> >
> > <link href="[% c.uri_for('/static/css/my_style.css') | html %]" rel="stylesheet">
>
> Assuming you're using Template Toolkit, you should use the "url"
> filter, not the "html" filter:
>
> <link href="[% c.uri_for('/static/css/my_style.css') | url %]"
> rel="stylesheet">

No.

First, if $c->uri_for gives you a URI which isn’t already correctly
URI-encoded, then it has a bug which should be reported. And if it does
give you correctly encoded URIs, as it should and probably does, then
re-encoding them will break any already-encoded parts.

Second, you are outputting URIs into HTML content, and URIs can contain
verbatim things that are metacharacters in HTML, such as ampersands.
Those need to be entity-escaped for HTML. If you aren’t doing that, then
you are producing broken HTML.

So what you are directing Trevor to do is broken – and not just once but
twice.

In practice, URIs that require escaping are uncommon and browsers go to
enormous lengths to understand broken HTML (and unescaped ampersands in
URIs are a very common problem), so you can go for a long time without
running these problems. But that code is still broken, and broken twice,
nonetheless.

Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/