diff --git a/src/Ssr/HttpGateway.php b/src/Ssr/HttpGateway.php index 62b92717..89560e66 100644 --- a/src/Ssr/HttpGateway.php +++ b/src/Ssr/HttpGateway.php @@ -3,20 +3,29 @@ namespace Inertia\Ssr; use Exception; +use Illuminate\Foundation\Vite; use Illuminate\Support\Facades\Http; class HttpGateway implements Gateway { + public function __construct( + private Vite $vite, + ) { + } + /** * Dispatch the Inertia page to the Server Side Rendering engine. */ public function dispatch(array $page): ?Response { - if (! config('inertia.ssr.enabled', true) || ! (new BundleDetector)->detect()) { + if ($this->vite->isRunningHot()) { + $url = file_get_contents($this->vite->hotFile()).'/render'; + } elseif (config('inertia.ssr.enabled', true) || (new BundleDetector)->detect()) { + $url = str_replace('/render', '', config('inertia.ssr.url', 'http://127.0.0.1:13714')).'/render'; + } else { return null; } - $url = str_replace('/render', '', config('inertia.ssr.url', 'http://127.0.0.1:13714')).'/render'; try { $response = Http::post($url, $page)->throw()->json();