Laravel Starter Kits
If you are using Laravel Starter Kits, Inertia SSR is supported through a build command:Add Server Entry-Point
To manually configure SSR without a Laravel starter kit, first create an SSR entry point file within your Laravel project.app.js file that makes sense to run in SSR mode, such as plugins or custom mixins.
Clustering
By default, the SSR server will run on a single thread. Clustering starts multiple Node servers on the same port, requests are then handled by each thread in a round-robin way. You may enable clustering by passing a second argument of options tocreateServer.
Client-Side Hydration
Setup Vite
Next, update your Vite configuration to build the new SSR entry point by adding assr property to Laravel’s Vite plugin configuration in your vite.config.js file.
Update NPM Script
Next, update thebuild script in your package.json file to also build your SSR entry point.
package.json
Running the SSR Server
Now that you have built both your client-side and server-side bundles, you should be able run the Node-based Inertia SSR server using the following command.--runtime option to specify which runtime you want to use. This allows you to switch from the default Node.js runtime to Bun.
Disabling SSR
Sometimes you may wish to disable server-side rendering for certain pages or routes in your application. You may do so by setting theinertia.ssr.enabled configuration value to false for the current request, typically in a service provider or middleware.
Deployment
When deploying your SSR enabled app to production, you’ll need to build both the client-side (app.js) and server-side bundles (ssr.js), and then run the SSR server as a background process, typically using a process monitoring tool such as Supervisor.
inertia:stop-ssr Artisan command. Your process monitor (such as Supervisor) should be responsible for automatically restarting the SSR server after it has stopped.
inertia:check-ssr Artisan command to verify that the SSR server is running. This can be helpful after deployment and works well as a Docker health check to ensure the server is responding as expected.
inertia.ssr.ensure_bundle_exists configuration value to false.