[Dancer-users] Exploring Best Practices for Route Definition
Carlos Ivan Sosa
gnusosa at gnusosa.net
Wed May 4 21:48:43 CEST 2011
On Wed, May 4, 2011 at 12:42 PM, J. Bobby Lopez <jbl at jbldata.com> wrote:
> Hello Dancers,
> I recently asked a question on #dancer regarding how to deal with trailing
> slashes on routes. There was a brief discussion which resulted, and I've
> copied the the discussion below in order to get some more input on the
> (with permission from gnusosa) please see the discussion below:
I proposed him to mail the list, since the channel does not log the discussions,
and it was something I couldn't answer as a know fact. I think the dev. team
might know better.
> 14:54 < jbl> curious how others treat the difference between 'route' and
> 'route/' in dancer. I'm often using
> '/some/route', but then if a user tries to access the app with
> http://site.com/some/route/' (with the trailing
> slash) it gives a 404 by default. What's the usual cure for this problem?
> 14:55 < gnusosa> jbl: Good Question.
> 14:59 < gnusosa> jbl: This is going to happen since the slash "/" is the one
> that difference the route from the route/
> 15:02 < jbl> right
> 15:03 < jbl> I'm just wondering if I should add a wildcard or redirect to
> catch trailing slashes, or if there is a setting
> somewhere that checks if there are no other characters after the slash, to
> just treat it as base route
> 15:03 < jbl> not sure I'm being clear on that :\
> 15:04 < jbl> I think I saw the use of regexs for routes somewhere, that
> might be a good option
> 15:06 < jbl> to do something like: get '/myroute[/]*$'
> 15:07 < jbl> or maybe even just strip the trailing slashes using a 'before'
> 15:07 < gnusosa> jbl: Probably.
> 15:07 < jbl> curse of tmtowtdi
> 15:08 < gnusosa> jbl: But all of these seems like too much hassle.
> 15:08 < gnusosa> jbl: What is the problem with sending some people to 404 :P
> 15:10 < jbl> I guess that if the URL doesn't have an extension "/route.cgi"
> then some people (maybe just me) may feel that
> URL is incomplete/incorrect/odd somehow. I guess they could go to a 404 if
> they type in the URL manually
> 15:11 < jbl> no real harm in that as long as the real URL works
> 15:11 < jbl> just feels off
> 15:11 < gnusosa> jbl: umm I understand now.
> 15:12 < jbl> and I remember at some point (back in the day) it was good
> practice to end URLs with a slash, if it wasn't
> going to a 'file'
I think the last ^
He is referring to the following
> 15:16 < gnusosa> jbl: You should email the mailing list
> dancer-users at perldancer.org with this issue. Best practices in the
> routes are a big deal.
> Dancer-users mailing list
> Dancer-users at perldancer.org
More information about the Dancer-users