128 lines
3.9 KiB
PHP
128 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
// use App\Domain\DomainContext; // HOTFIX: Temporär deaktiviert
|
|
use App\Domain\EarlyDomainParser;
|
|
use Illuminate\Cache\RateLimiting\Limit;
|
|
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\RateLimiter;
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
class RouteServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* The path to the "home" route for your application.
|
|
*
|
|
* @var string
|
|
*/
|
|
public const HOME = '/';
|
|
|
|
/**
|
|
* The controller namespace for the application.
|
|
*
|
|
* @var string|null
|
|
*/
|
|
protected $namespace = 'App\\Http\\Controllers';
|
|
|
|
/**
|
|
* Define your route model bindings, pattern filters, etc.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
$this->configureRateLimiting();
|
|
|
|
$this->routes(function () {
|
|
// API-Routen werden global geladen
|
|
Route::domain('api.' . config('app.domain') . config('app.tld_care'))
|
|
->middleware('api')
|
|
->namespace($this->namespace)
|
|
->group(base_path('routes/api.php'));
|
|
|
|
// Web-Routen werden domain-bewusst geladen
|
|
Route::middleware('web')
|
|
->namespace($this->namespace)
|
|
->group(function () {
|
|
$this->loadDomainAwareRoutes();
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Lädt Routen basierend auf der domains.php Konfiguration.
|
|
* Vereinfachter Ansatz ohne DomainContext-Abhängigkeit
|
|
*/
|
|
protected function loadDomainAwareRoutes(): void
|
|
{
|
|
$request = $this->app->make('request');
|
|
$this->loadSharedRoutes();
|
|
// Lade alle Domain-spezifischen Routen
|
|
// Die Domain-Logik wird von SubdomainResolver Middleware behandelt
|
|
$domainType = EarlyDomainParser::getCurrentDomainType($request->getHost());
|
|
|
|
$routesToLoad = match ($domainType) {
|
|
'main' => ['main'],
|
|
'main-shop' => ['shop', 'portal'],
|
|
'user-shop' => ['user-shop', 'portal'],
|
|
'crm' => ['crm'],
|
|
'portal' => ['portal'],
|
|
'checkout' => ['checkout'],
|
|
'unknown' => ['main'], // Fallback für unbekannte Domains
|
|
default => ['main'],
|
|
};
|
|
foreach ($routesToLoad as $routeType) {
|
|
$this->loadDomainRoutes($routeType, $routeType . '.php');
|
|
}
|
|
|
|
if (config('app.debug')) {
|
|
\Log::channel('domain')->info('Domain-aware routes loaded', [
|
|
'domain_type' => $domainType,
|
|
'routes_loaded' => $routesToLoad,
|
|
'host' => EarlyDomainParser::parseDomain()['host'],
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Lädt eine spezifische Routendatei für eine Domain.
|
|
*/
|
|
protected function loadDomainRoutes(string $domainType, string $fileName): void
|
|
{
|
|
$routePath = base_path('routes/domains/' . $fileName);
|
|
|
|
if (file_exists($routePath)) {
|
|
Route::group([], $routePath);
|
|
} else {
|
|
if (config('app.debug')) {
|
|
\Log::channel('domain')->warning('Domain route file not found', [
|
|
'domain_type' => $domainType,
|
|
'file_path' => $routePath,
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Lädt Routen, die auf allen Domains verfügbar sein sollen.
|
|
*/
|
|
protected function loadSharedRoutes(): void
|
|
{
|
|
// Lädt Routen, die auf allen Domains verfügbar sein sollen.
|
|
Route::group([], base_path('routes/shared/common.php'));
|
|
}
|
|
|
|
/**
|
|
* Konfiguriert die Rate-Limiter für die Anwendung.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function configureRateLimiting()
|
|
{
|
|
RateLimiter::for('api', function (Request $request) {
|
|
return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
|
|
});
|
|
}
|
|
}
|