Skip to content

SSR gateway

The SSR gateway renders the first visit on the server. Configure it with the ssrGateway property of the inertia component. See the server-side rendering guide.

HttpGateway

Crenspire\Yii2Inertia\Ssr\HttpGateway posts the page object to the Inertia SSR server.

Properties

PropertyTypeDefaultDescription
urlstring'http://127.0.0.1:13714'Base URL of the production SSR server (POST /render, GET /health)
devServerUrlstring|nullnullVite dev server URL; pages are rendered through its /__inertia_ssr endpoint. Filled in from vite.devServerUrl when not set
bundlestring|nullnullPath or alias of the SSR bundle; SSR is skipped when the file is missing (unless the dev server is used)
timeoutfloat5.0Seconds to wait for the server
throwOnErrorboolfalseThrow an SsrException instead of logging failures

Methods

php
dispatch(array $page): ?SsrResponse
isHealthy(): bool

dispatch() returns null when rendering is skipped or fails, which falls back to client-side rendering.

Gateway interface

php
namespace Crenspire\Yii2Inertia\Ssr;

interface Gateway
{
    public function dispatch(array $page): ?SsrResponse;
}

SsrResponse

php
final class SsrResponse
{
    public readonly string $head;  // HTML for the <head>
    public readonly string $body;  // HTML of the application, including the page data
}

SsrException

Thrown by HttpGateway when throwOnError is enabled. $exception->details contains the error reported by the SSR server (error, type, hint, sourceLocation, ...).

Released under the MIT License.