Configuration of Svelte SSR Server

The Svelte SSR server is enabled by default:

use_ssr_server: true

If set to false, it uses the Fallback Renderer. This is intended for view tests and is much slower because it has to launch node for each rendering.

It starts and stops with Puma.

If everything is running as expected, there shouldn’t be anything else to do.

Troubleshooting

If the ping fails, it breaks the boot process.

For check processes on a production server, for example, by running ps aux | grep svelte-ssr-server you will find a line like:

christian        99874   0.0  0.2 412162928  40384   ??  S    11:17AM   0:00.08 node node_modules/@csedl/svelte-on-rails/bin/svelte-ssr-server.js /Users/christian/tmp/sockets/svelte-ssr.sock

This shows the socket on which the Svelte SSR server is listening. If you have different environments for the same user on a production server, or if you are running tests and development in parallel on a development server, you will see multiple instances, one for each socket.

You can start the Svelte SSR server manually by running:

SVELTE_SSR_SERVER_LOGFILE=/path/to_logfile node bin/svelte-ssr-server.js 3001

SVELTE_SSR_SERVER_LOGFILE is optional.

The gem starts the Svelte SSR server with a log file. However, the log file is always shortened to n lines. Depending on the environment. It is longer for production and shorter for development. So, you don’t need to worry about a steadily growing log file.

When the first argument contains only integers, e.g. 3001, it is interpreted as the port number for localhost. This is for development purposes.

Instead of the port number, you can pass the path to a socket file. This is how it is used in production.

The gem starts the Svelte SSR server, on booting rails, from within the app, by:

SVELTE_SSR_SERVER_LOGFILE=/rails-root/log/svelte-ssr-server.log node node_modules/@csedl/svelte-on-rails/bin/svelte-ssr-server.js /path/to/socket/svelte-ssr.sock

/path/to/socket is generated! The Logic is in lib/svelte_on_rails/ssr_server.rb#socket_path

First, it tries to create it within the apps tmp/sockets directory. This likely fails as unix systems restrict the length of the path. Then, it falls back to /tmp/svelte-ssr/<first-10-chars-of-app-name>-<Rails-env>-<Process-id>.sock


Copyright © 2025-2027 sedlmair.ch. Distributed by MIT license.