diff --git a/Jenkinsfile b/Jenkinsfile index 7631a8a..ea97f53 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -129,7 +129,9 @@ pipeline { sleep 5 docker exec ntspi-php php artisan inertia:stop-ssr || true sleep 2 - docker exec ntspi-php php artisan inertia:start-ssr || true + docker exec -d ntspi-php sh -c "php artisan inertia:start-ssr > /tmp/ssr-server.log 2>&1" + sleep 3 + docker exec ntspi-php php artisan inertia:check-ssr || true ''' } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 8c13710..4a91cf7 100755 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -45,8 +45,10 @@ use App\Services\App\Cache\SliderCacheService; use App\Services\App\Cache\SubSectionCacheService; use App\Ship\Contracts\SeoServiceInterface; use App\Ship\Services\SeoPageService; +use App\Ship\Ssr\SafeSsrGateway; use Carbon\Carbon; use Filament\Facades\Filament; +use Inertia\Ssr\Gateway; use Filament\Support\Facades\FilamentView; use Filament\Tables\View\TablesRenderHook; use Illuminate\Database\Eloquent\Factories\Factory; @@ -65,6 +67,7 @@ class AppServiceProvider extends ServiceProvider public function register(): void { $this->app->bind(SeoServiceInterface::class, SeoPageService::class); + $this->app->bind(Gateway::class, SafeSsrGateway::class); } /** diff --git a/app/Ship/Ssr/SafeSsrGateway.php b/app/Ship/Ssr/SafeSsrGateway.php new file mode 100644 index 0000000..f26d524 --- /dev/null +++ b/app/Ship/Ssr/SafeSsrGateway.php @@ -0,0 +1,86 @@ +shouldDispatch()) { + return null; + } + + if (! $this->isServerAvailable()) { + return null; + } + + try { + $response = Http::timeout(5) + ->retry(1, 200) + ->post($this->getUrl('/render'), $page) + ->throw() + ->json(); + } catch (Exception $e) { + if ($e instanceof StrayRequestException) { + throw $e; + } + + $this->serverAvailable = false; + + return null; + } + + if (is_null($response)) { + return null; + } + + $body = $response['body'] ?? ''; + $head = $response['head'] ?? []; + + if (empty($body) && empty($head)) { + return null; + } + + return new Response( + implode("\n", $head), + $body + ); + } + + public function isHealthy(): bool + { + return $this->isServerAvailable(); + } + + private function isServerAvailable(): bool + { + if ($this->checked) { + return $this->serverAvailable; + } + + $this->checked = true; + + try { + $this->serverAvailable = Http::timeout(1) + ->get($this->getUrl('/health')) + ->successful(); + } catch (Exception $e) { + if ($e instanceof StrayRequestException) { + throw $e; + } + + $this->serverAvailable = false; + } + + return $this->serverAvailable; + } +} diff --git a/config/inertia.php b/config/inertia.php new file mode 100644 index 0000000..c7aaf59 --- /dev/null +++ b/config/inertia.php @@ -0,0 +1,11 @@ + [ + 'enabled' => env('INERTIA_SSR_ENABLED', true), + 'url' => env('INERTIA_SSR_URL', 'http://127.0.0.1:13714'), + 'ensure_bundle_exists' => env('INERTIA_SSR_ENSURE_BUNDLE_EXISTS', true), + ], + + 'use_script_element_for_initial_page' => false, +]; diff --git a/resources/js/Pages/Client/Departments/Show.vue b/resources/js/Pages/Client/Departments/Show.vue index 0d55fd7..ff163fb 100755 --- a/resources/js/Pages/Client/Departments/Show.vue +++ b/resources/js/Pages/Client/Departments/Show.vue @@ -16,7 +16,7 @@