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

Bug: Inconsistent hostname/subdomain limitation in Routing #7214

Open
kenjis opened this issue Feb 2, 2023 · 4 comments
Open

Bug: Inconsistent hostname/subdomain limitation in Routing #7214

kenjis opened this issue Feb 2, 2023 · 4 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@kenjis
Copy link
Member

kenjis commented Feb 2, 2023

CodeIgniter version: 4.3.1

(1) hostname takes precedence over subdomain
if a route has both:

$routes->get('/', 'Home::index');
$routes->get('/', 'Media::index', ['hostname' => 'media.example.com:8888', 'subdomain' => '*']);

http://media.example.com:8888/ci431/public/App\Controllers\Media::index
http://user.example.com:8888/ci431/public/App\Controllers\Home::index

(2) subdomain takes precedence over hostname
if two routes matches:

$routes->get('/', 'Home::index');
$routes->get('/', 'Media::index', ['hostname' => 'media.example.com:8888']);
$routes->get('/', 'All::index', ['subdomain' => '*']);

http://media.example.com:8888/ci431/public/App\Controllers\All::index
http://user.example.com:8888/ci431/public/App\Controllers\All::index

@kenjis kenjis added bug Verified issues on the current code behavior or pull requests that will fix them dev and removed dev labels Feb 2, 2023
@iRedds
Copy link
Collaborator

iRedds commented Feb 3, 2023

On the forum, I already suggested the idea of ​​creating a unique key for registering a route, like domain + path. (As it turned out, the same is used in Laravel).

This would solve the existing problem. And it would also be possible to create a cache of routes, which in my opinion would be a good solution if the application uses many modules with routes.

@kenjis
Copy link
Member Author

kenjis commented Feb 3, 2023

First of all, I think it is necessary to determine whether this is really a bug
and decide what the specification should be.

What about router implementations other than Laravel?

@iRedds
Copy link
Collaborator

iRedds commented Feb 3, 2023

If the "hostname" or "subdomain" options are specified and the path matches, then the route will be overwritten by the last one added. This is what happens in example 2.

If you're expecting Media::index but have All::index, then yes, it's a bug.

Symfony - route name
Yii - route name ?? methods + domain + pattern
That is, a unique route key is used.

As an alternative, we may not use an associative array.

@ping-yee
Copy link
Contributor

So... is there a consensus here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

3 participants