Multi-Domain-Asset-Infrastruktur: geteilte Vite-Konfiguration und DomainAssetContext
- vite.shared.js als gemeinsame Quelle fuer Ports, Hot-Files, HMR-Hosts und CORS-Origins der beiden Vite-Builds (Portal/Web) - App\Support\DomainAssetContext kapselt die Vite-Build-Directory- Konfiguration pro Domain (ThemeServiceProvider + Auth-Layout nutzen ihn) - Tailwind-Portal-Content-Globs auf die tatsaechliche View-Struktur gezogen - Dev-Beispiel-Routen + Tests (DomainAssetContextTest, DevExampleRoutesTest) - Aufraeumen: versehentliche Leerdatei dev:web entfernt Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
4bb9094207
commit
0efabaf446
15 changed files with 485 additions and 109 deletions
145
app/Support/DomainAssetContext.php
Normal file
145
app/Support/DomainAssetContext.php
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Vite;
|
||||
|
||||
class DomainAssetContext
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $defaults
|
||||
* @param array<string, array<string, mixed>> $configuredDomains
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function resolve(
|
||||
string $host,
|
||||
array $defaults,
|
||||
array $configuredDomains,
|
||||
?string $themeOverride = null,
|
||||
?Request $request = null,
|
||||
): array {
|
||||
if ($themeOverride !== null && isset($configuredDomains[$themeOverride])) {
|
||||
return array_merge($defaults, $configuredDomains[$themeOverride]);
|
||||
}
|
||||
|
||||
$portalHost = (string) config('domains.domain_portal');
|
||||
|
||||
if ($host === $portalHost) {
|
||||
$request ??= request();
|
||||
|
||||
if (self::isBackendRequest($request)) {
|
||||
return array_merge($defaults, $configuredDomains['portal'] ?? $defaults);
|
||||
}
|
||||
|
||||
return array_merge($defaults, $configuredDomains['pressekonto'] ?? $defaults);
|
||||
}
|
||||
|
||||
foreach ($configuredDomains as $config) {
|
||||
if (! is_array($config)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (($config['domain_name'] ?? null) === $host) {
|
||||
return array_merge($defaults, $config);
|
||||
}
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
public static function isBackendRequest(Request $request): bool
|
||||
{
|
||||
if ($request->routeIs(
|
||||
'dashboard',
|
||||
'login',
|
||||
'register',
|
||||
'password.*',
|
||||
'verification.*',
|
||||
'two-factor.*',
|
||||
'magic-links.*',
|
||||
'me.*',
|
||||
'settings.*',
|
||||
'press-releases.preview',
|
||||
)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$backendPrefixes = [
|
||||
'admin',
|
||||
'customer',
|
||||
'dashboard',
|
||||
'login',
|
||||
'register',
|
||||
'forgot-password',
|
||||
'reset-password',
|
||||
'magic-login',
|
||||
'user',
|
||||
'settings',
|
||||
'flux',
|
||||
'livewire',
|
||||
];
|
||||
|
||||
$path = trim($request->path(), '/');
|
||||
|
||||
foreach ($backendPrefixes as $prefix) {
|
||||
if ($path === $prefix || str_starts_with($path, "{$prefix}/")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function usesWebAssets(string $assetsDir): bool
|
||||
{
|
||||
return $assetsDir === 'build/web';
|
||||
}
|
||||
|
||||
public static function hotFilePath(string $assetsDir): string
|
||||
{
|
||||
return self::usesWebAssets($assetsDir)
|
||||
? public_path('hot-web')
|
||||
: public_path('hot-portal');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $domainConfig
|
||||
*/
|
||||
public static function configureVite(array $domainConfig): void
|
||||
{
|
||||
$assetsDir = (string) ($domainConfig['assets_dir'] ?? 'build/portal');
|
||||
|
||||
Vite::useBuildDirectory($assetsDir);
|
||||
Vite::useHotFile(self::hotFilePath($assetsDir));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $domainConfig
|
||||
*/
|
||||
public static function staticAssetOrigin(array $domainConfig): string
|
||||
{
|
||||
return (string) ($domainConfig['url'] ?? config('app.url'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $domainConfig
|
||||
*/
|
||||
public static function viteDevServerUrl(array $domainConfig): string
|
||||
{
|
||||
if (isset($domainConfig['asset_url'])) {
|
||||
return (string) $domainConfig['asset_url'];
|
||||
}
|
||||
|
||||
$assetsDir = (string) ($domainConfig['assets_dir'] ?? 'build/portal');
|
||||
|
||||
return self::usesWebAssets($assetsDir)
|
||||
? 'https://assets.pressekonto.test'
|
||||
: 'https://assets.pressekonto.test';
|
||||
}
|
||||
|
||||
public static function isViteDevServerRunning(string $assetsDir): bool
|
||||
{
|
||||
return is_file(self::hotFilePath($assetsDir));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue