multi-tenant: 5.4 breaks multiple hostnames for website

Description

First of, thanks for the amazing package ! I’ve been using for awhile and it saved me a lot of time !

Migrating to Laravel 5.8 and consequently to multi-tenant 5.4, I’ve been experiencing an unexpected behavior with my hostnames, though.

Basically I have 2 hostnames (one for internal use and one for external, using a NOIP domain) for the same Website.

The internal hostname works just fine with a fake domain, registered in the etc/hosts file, but since the upgrade, I cannot access it from the external domain.

Example:

  1. sub.domain.com
  2. sub.noip.com

Access through the sub.domain.com on my local machine works fine, but trying to access it from the sub.noip.com, I get redirected to the sub.domain.com that does not exist, and can’t access the system (which I could on 5.3).


Actual behavior

Can’t access the Website by secondary Hostnames.

Expected behavior

Be able to access the Website by all its Hostnames.


Information

  • hyn/multi-tenant version: 5.4
  • laravel version: 5.8

Debugging

I’ve been playing around with the source code and trying to check all the changes made from one version to the other and I think I’ve tracked down the problem to the Hyn\Tenancy\Listeners\URL\UpdateAppUrl class.

More specifically, on line 40:

$hostname = $event->hostname ?? $event->website->hostnames->first();

So basically it’s just grabbing the first hostname registered for the website, which I believe shouldn’t be true, I guess we should first verify if the request’s host matches any of the hostname’s FQDN, so basically just do something like this:

$hostname = $event->hostname
    ?? $event->website->hostnames->firstWhere('fqdn', optional(request())->getHost())
    ?? $event->website->hostnames->first();

I’m not sure if the current behavior is actually the intended one or if the above solution would be ok (it seems to work alright), if so I could also open a PR.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 32 (31 by maintainers)

Most upvoted comments

I will assert that the workaround posted by @isecchin in first post above (https://github.com/tenancy/multi-tenant/issues/750#issue-421311480) correctly resolves the stated problem. I will re-state it again, for clarity: when a website has multiple hostnames, this change will correctly “keep” the URL that the visitor came in on, instead of switching unexpectedly to the “first found by Eloquent”. For me this is critical. @luceos will you accept a PR with that fix?

IMO any concerns about “other ports” should be handled separately. Similarly, there are already other discussions about multiple firing of events. I wouldn’t muddy this issue with further discussion about those.