From adc1b5e73ee52b940f2db794ed70efa44ad42b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sat, 12 Oct 2019 14:18:57 +0200 Subject: [PATCH] wip --- src/Middleware/InitializeTenancy.php | 10 ++++++---- src/TenancyServiceProvider.php | 9 ++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Middleware/InitializeTenancy.php b/src/Middleware/InitializeTenancy.php index 3bc383ba..bc1cbb1c 100644 --- a/src/Middleware/InitializeTenancy.php +++ b/src/Middleware/InitializeTenancy.php @@ -28,10 +28,12 @@ class InitializeTenancy */ public function handle($request, Closure $next) { - try { - tenancy()->init($request->getHost()); - } catch (TenantCouldNotBeIdentifiedException $e) { - ($this->onFail)($e); + if (! in_array($request->getHost(), config('tenancy.exempt_domains', []), true)) { + try { + tenancy()->init($request->getHost()); + } catch (TenantCouldNotBeIdentifiedException $e) { + ($this->onFail)($e); + } } return $next($request); diff --git a/src/TenancyServiceProvider.php b/src/TenancyServiceProvider.php index 7f8e86ad..acc3fdac 100644 --- a/src/TenancyServiceProvider.php +++ b/src/TenancyServiceProvider.php @@ -5,8 +5,10 @@ declare(strict_types=1); namespace Stancl\Tenancy; use Illuminate\Cache\CacheManager; +use Illuminate\Contracts\Http\Kernel; use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; +use Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains; use Stancl\Tenancy\TenancyBootstrappers\FilesystemTenancyBootstrapper; class TenancyServiceProvider extends ServiceProvider @@ -79,8 +81,13 @@ class TenancyServiceProvider extends ServiceProvider $this->loadRoutesFrom(__DIR__ . '/routes.php'); + $this->app->make(Kernel::class)->prependMiddleware([ + Middleware\InitializeTenancy::class, + ]); + Route::middlewareGroup('tenancy', [ - \Stancl\Tenancy\Middleware\InitializeTenancy::class, + /** Prevent access from tenant domains to central routes and vice versa. */ + Middleware\PreventAccessFromTenantDomains::class, ]); $this->app->singleton('globalUrl', function ($app) {