Тип сервиса
Сервис Node.js (SvelteKit)
Среда выполнения Node.js для сборки приложений SvelteKit из исходного кода, с рабочим пространством разработки.
Этот сервис запускает ваш код: его образ собирается из Git-репозитория, а каждая сборка развёртывается в окружение.
В StackMaster
Как Node.js (SvelteKit) работает в StackMaster
How the application is started
The image built by the service's Dockerfile starts the application with npm run start, from /usr/src/app. package.json must define a start script.
- The application must listen on port 3000, on all interfaces. That is the port of the service's HTTP endpoint. The service sets
NODE_PORTto that number; it does not setPORT. ReadNODE_PORT, or default to 3000. NODE_ENVisdevelopmentin environments of typedevandproductionin every other type.
Build
The service's Dockerfile only copies the build context to /usr/src/app. It does not run npm install. Dependencies, and any compiled output, must be produced by the pipeline before the image is built, for example with wodby ci run -- npm ci, so that node_modules is part of what is copied. An image built without node_modules cannot load the application's dependencies.
A pipeline that passes a Dockerfile from the repository (wodby ci build node -f Dockerfile) uses that file instead.
The service declares no volume of its own: files written inside the container are lost when it is replaced.
Linked services
Links to other services reach the application as environment variables. Nothing in the image reads them: the application reads them itself. Do not hardcode hosts or credentials.
| Link | Variables |
|---|---|
| Database (MariaDB, MySQL or PostgreSQL) | DB_HOST, DB_PORT, DB_NAME (also DB_DATABASE), DB_USERNAME, DB_PASSWORD, DB_DRIVER (also DB_CONNECTION) |
SMTP_HOST, SMTP_PORT | |
| Redis or Valkey | REDIS_HOST, REDIS_PORT, REDIS_PASSWORD |
| OpenTelemetry Collector | OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_PROTOCOL (http/protobuf), OTEL_EXPORTER_OTLP_HEADERS (the Collector's ingest token) |
All links are optional. A variable is present only while its link exists and the linked service is enabled. The mail link carries no credentials. The OpenTelemetry variables are the standard SDK settings: an application or agent that uses an OpenTelemetry SDK exports to the Collector without further configuration; set OTEL_SERVICE_NAME to name the application in traces.
Environment
WODBY_HOSTSis a JSON array of the environment's hosts, not a comma-separated string.WODBY_PRIMARY_HOSTandWODBY_PRIMARY_URLare the canonical ones for links generated outside a request.WODBY_APP_SERVICE_NAMEis this service's host name inside the environment. Other services reach the application at that name on port 3000.WODBY_ENV_TYPEtells a development environment from a production-like one.
In a development workspace
- The checkout is mounted at
/usr/src/appand served as it is on disk. - Workspace setup installs dependencies with
workspace-node prepare. The package manager is taken frompackageManagerinpackage.json, otherwise from the lockfile:pnpm-lock.yamlmeans pnpm,yarn.lockmeans Yarn, anything else npm. Installs follow the lockfile exactly (npm ci,--frozen-lockfile,--immutable), with development dependencies. Run it again after changing dependencies. - The application is started with the
devscript ofpackage.jsonwhen there is one, otherwise withstart.WORKSPACE_NODE_COMMANDon the service replaces that command. NODE_ENVis alwaysdevelopmenthere, whatever the environment type.PORTis set, toNODE_PORTunless given, andHOSTto0.0.0.0.- A saved file is picked up without a restart or a deployment. A
devscript is expected to watch the files itself. Astartscript runs the application once, so the checkout is watched for it: when a file changes, the application is stopped and started again in the same container, within a few seconds.node_modules,.git,.pnpm-store,.next,dist,buildandcoverageare not watched. A command set withWORKSPACE_NODE_COMMANDis run as it is, without that watcher;WORKSPACE_NODE_WATCH=0turns the watcher off. For scripts with their own watcher,CHOKIDAR_USEPOLLING,CHOKIDAR_INTERVALandWATCHPACK_POLLINGare set, because a checkout on network storage needs polling.WORKSPACE_POLL_INTERVALchanges the interval,WORKSPACE_POLLING=0turns this off. node_modules/and/.pnpm-store/are kept out of Git status without touching.gitignore.- A change to variables or linked services still needs a deployment of the environment.
Check the result
curl -s -o /dev/null -w '%{http_code}' "localhost:$NODE_PORT"from the container shows whether the application answers on the expected port.printenv | grep -E '^(DB|SMTP|REDIS)_' | cut -d= -f1lists the link variables that are present.
SvelteKit on Wodby
What this service adds to the Node.js service it is based on. It targets SvelteKit 3, which needs Node.js 22.17 or later; every Node.js version the service offers (22, 24, 26) qualifies.
Build and start
The service's Dockerfile copies the build context to /usr/src/app, runs npm run build and starts the container with npm run start. package.json must define both scripts.
- The supported production output is
@sveltejs/adapter-node: setadapter: adapter()in thesveltekit()plugin invite.config.ts, build withvite buildand start withnode build. SvelteKit 3 reads its configuration from thesveltekit()Vite plugin; it does not readsvelte.config.js. - The Dockerfile does not install dependencies. The pipeline does it before the image is built (
wodby ci run -- npm ci), andnode_modulesis copied with the code.@sveltejs/kit, the adapter, Vite and Svelte may stay indevDependencies: adapter-node bundles them intobuild/. Packages independenciesare loaded fromnode_modulesat runtime, which the image contains. npm run buildruns while the image is built. Runtime variables of the service, including the link variables and secrets, are not available to it. See "Environment variables" for how to read them.- The image build leaves out
.git,.gitignore,buildand.svelte-kit. The build createsbuild/and.svelte-kit/anew. - The application must listen on port 3000. adapter-node listens on
PORTand defaults to 3000; leavePORTunset.
Environment variables
SvelteKit 3 reads environment variables declared in src/env.ts with defineEnvVars from @sveltejs/kit/env, and server code imports them from $app/env/private. The $env/dynamic/* and $env/static/* modules still work but are deprecated.
- Keep variables dynamic, the default. A variable with
static: trueis inlined at build time, when the service's runtime variables do not exist. - SvelteKit validates the declared variables when the server starts and also during
vite build. A variable declared without aschemamust be set, so the image build fails. Give every runtime variable a schema that accepts a missing value, for exampleschema: (value) => value || undefined, or checkbuildingfrom$app/envin the schema and require the value only when it is false. - Variables declared with
public: truereach the browser through$app/env/public. Never mark a secret public. - Server code may also read
process.envat request time.
Proxy, origin and form actions
Wodby's gateway terminates TLS, keeps the request's Host header and sets X-Forwarded-Proto and X-Forwarded-For. The service sets adapter-node's variables for that:
| Variable | Value | Effect |
|---|---|---|
PROTOCOL_HEADER | x-forwarded-proto | url.origin is the scheme the visitor used plus the Host header, so it is right for every domain of the environment. Requests without the header, such as checks inside the environment, are treated as https. |
ADDRESS_HEADER | x-forwarded-for | getClientAddress() returns the visitor's address as the gateway recorded it. |
XFF_DEPTH | 1 | Only the right-most X-Forwarded-For entry, which the gateway appends, is trusted. |
SHUTDOWN_TIMEOUT | 25 | After SIGTERM, open requests get 25 seconds before their connections are closed, within the 30 second grace period. Then the sveltekit:shutdown process event runs. |
- SvelteKit 3 always checks the
Originheader of form submissions (form actions andPOST,PUT,PATCH,DELETEwith a form content type) in production. The request's own origin passes, so every domain of the environment works. Do not setpaths.origininvite.config.ts: it is fixed at build time and allows only one domain. Usecsrf.trustedOriginsonly for other sites that must post to the application. getClientAddress()throws for a request withoutX-Forwarded-For, which is a request that did not pass the gateway, such as a check from inside the environment. Do not call it unconditionally inhandleor in/healthz.- Request bodies are limited to 512 KB by default. Set
BODY_SIZE_LIMIT(for example10M, orInfinity) on the service for larger uploads. - Do not set
HOST_HEADER,PORT_HEADERorORIGIN. SvelteKit 3's adapter-node no longer readsORIGIN.
Variables the service sets
| Variable | Meaning |
|---|---|
NODE_ENV | production in every environment type, including dev. The Node.js service's development value for dev is replaced, because the container runs a production build. |
PROTOCOL_HEADER, ADDRESS_HEADER, XFF_DEPTH, SHUTDOWN_TIMEOUT | See "Proxy, origin and form actions". |
WORKSPACE_NODE_COMMAND | workspace-node vite-start, the start command of a development workspace. |
Linked services
The service adds no link variables. The database, mail and Redis or Valkey variables of the Node.js service apply unchanged. Declare the ones the application uses in src/env.ts with a schema that accepts a missing value, because the links are optional and the variables do not exist during the build. They never reach the browser unless declared public.
Health check
The boilerplate answers GET /healthz with ok from src/routes/healthz/+server.ts, without touching other services. Its post-deployment check requests http://${WODBY_APP_SERVICE_NAME}:3000/healthz.
In a development workspace
- The application is started through Vite's JavaScript API with the project's own
vite.config.ts, not through thedevscript ofpackage.json. Options in that script do not apply. Host, port,strictPortand file polling are set on top of the project's configuration, in memory; no file is written.vitemust be a dependency of the project. - The development server listens on
0.0.0.0:3000. Do not change the port in the project configuration. - Vite rejects requests for host names it does not know. Add the environment's hosts to
server.allowedHosts:WODBY_HOSTSholds them as a JSON array, andWODBY_APP_SERVICE_NAMEis the internal name. The boilerplate'svite.config.tsdoes this. - File watching uses polling, so saved files and new route files are picked up without a restart. SvelteKit regenerates
.svelte-kit/, including the./$typesroute types, while the development server runs.npm ciin the workspace's preparation runs thepreparescript,svelte-kit sync, which creates it first. NODE_ENVisdevelopmenthere. The origin check of form submissions does not run in development./build/and/.svelte-kit/are kept out of Git status, in addition to the Node.js service's paths.- The image build's
npm run builddoes not run in a workspace.
Обзор
Технический профиль Node.js (SvelteKit)
Версии
Основан на
Репозиторий исходного кода
Публичный Helm-чарт
Стеки
Стеки, в которые входит Node.js (SvelteKit)
CI/CD
Сборка Node.js (SvelteKit) из Git-репозитория
SvelteKit Boilerplate
Используйте его как есть или клонируйте в свой Git-аккаунт.
wodby/sveltekit-boilerplateCI-провайдеры
StackMaster CI встроен в платформу: пайплайн описывается в файле .wodby/pipeline.yml в репозитории. Для подключённого репозитория те же шаги может выполнять внешний CI-провайдер с помощью StackMaster CLI.
Реестры контейнеров
Собранные образы по умолчанию попадают в StackMaster Registry или во внешний реестр, подключённый как интеграция.
Переменные окружения из интеграций
Интеграция с переменными один раз сохраняет учётные данные стороннего сервиса. Подключите её к Node.js (SvelteKit), и StackMaster передаст их в контейнер как переменные окружения во время работы, а не при сборке образа.
Конфигурация
Конфигурация сервиса Node.js (SvelteKit)
Технические домены
Связи сервиса
Каждая связь — это подключение Node.js (SvelteKit) к другому сервису. На какой сервис указывает связь, задаёт стек. На карточках перечислены публичные сервисы, которые подходят для каждой связи.
db
Сервисы, которые подходят для этой связи
sendmail
Сервисы, которые подходят для этой связи
redis
Сервисы, которые подходят для этой связи
otel
Сервисы, которые подходят для этой связи