Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a prefix makes a subtle, non-intuitive change in routing #1429

Closed
kenneth-olwing opened this issue Jan 24, 2018 · 3 comments
Closed

Comments

@kenneth-olwing
Copy link

Hi, as a beginner with Dancer2 I caught the below - no idea if it's a bug or a expected feature, but for me it was non-intuitive given 'principle of least surprise'...

Consider this simple helloworld.pl:

use Dancer2;
prefix undef;
get '/' => sub { 'hello' };
get '/foo' => sub { 'world' };
dance;

Starting this makes browsing to http://localhost:3000 perfectly fine (renders 'hello') as well as http://localhost:3000/foo (renders 'world'). So far so good.

Now consider that I want to use a prefix:

use Dancer2;
prefix '/myprefix';
get '/' => sub { 'hello' };
get '/foo' => sub { 'world' };
dance;

My expectation here was that the only change needed when browsing is adding the prefix to the URL. However, browsing to http://localhost:3000/myprefix now gives me 404 - I need to explicitly add the trailing '/' to make it work again, e.g. http://localhost:3000/myprefix/. However, http://localhost:3000/myprefix/foo works as before.

So it's a subtle and fairly minor change in behavior. I haven't checked the code but assume it's an artifact of basically just smooshing the prefix and the route together - would it be relevant to add special case handling for the top-level '/' route when a prefix is involved?

Thanks,

ken1

@simbabque
Copy link
Contributor

The paths /myprefix and /myprefix/ are not the same. The first, without the slash, usually means a file. The second, with the slash, means a directory.

There are a lot of discussions on whether those should point to the same thing in the SEO world. Take a look at https://webmasters.googleblog.com/2010/04/to-slash-or-not-to-slash.html, for example. (By no means am I an authority, that was the first credible source that came up when googling).

Funny enough, there is a https://metacpan.org/pod/Plack::Middleware::TrailingSlashKiller, which removes all the trailing slashes on the way in.

But then there is #593, where @xsawyerx explains why the two are different. So it seems it's by-design and a feature.

@kenneth-olwing
Copy link
Author

Thanks for the insight! Now I understand the issue.

@xsawyerx
Copy link
Member

Closed as a non-issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants