From c30547a3318fd18ae94fd381ee6817f018310e26 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 15 Jan 2018 22:48:53 +0200 Subject: [PATCH] Merge subdomain fix --- app/Http/Middleware/DatabaseLookup.php | 5 +++++ app/Libraries/Utils.php | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Http/Middleware/DatabaseLookup.php b/app/Http/Middleware/DatabaseLookup.php index 345a063805a2..b01f68e9b031 100644 --- a/app/Http/Middleware/DatabaseLookup.php +++ b/app/Http/Middleware/DatabaseLookup.php @@ -58,6 +58,11 @@ class DatabaseLookup } elseif ($guard == 'account') { if ($key = request()->account_key) { LookupAccount::setServerByField('account_key', $key); + } else { + $subdomain = Utils::getSubdomain(\Request::server('HTTP_HOST')); + if ($subdomain != 'app') { + LookupAccount::setServerByField('subdomain', $subdomain); + } } } elseif ($guard == 'license') { config(['database.default' => DB_NINJA_1]); diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index 80ac648fe171..6464043d6b3f 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -1002,8 +1002,12 @@ class Utils $parts = parse_url($url); $subdomain = ''; - if (isset($parts['host'])) { - $host = explode('.', $parts['host']); + if (isset($parts['host']) || isset($parts['path'])) { + if (isset($parts['host'])) { + $host = explode('.', $parts['host']); + } else { + $host = explode('.', $parts['path']); + } if (count($host) > 2) { $subdomain = $host[0]; }