Сервис приложения
Сервисы/Node.js (Strapi)

Сервис Node.js (Strapi)

Среда выполнения Node.js для сборки headless CMS Strapi из исходного кода со связью с базой данных, хранилищем загрузок и рабочим пространством разработки.

Этот сервис запускает ваш код: его образ собирается из Git-репозитория, а каждая сборка развёртывается в окружение.

В StackMaster

Как Node.js (Strapi) работает в StackMaster

What Wodby sets up for an application that runs on this service. Check it before changing the start command, the port or connection settings in the code.

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_PORT to that number; it does not set PORT. Read NODE_PORT, or default to 3000.
  • NODE_ENV is development in environments of type dev and production in 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.

LinkVariables
Database (MariaDB, MySQL or PostgreSQL)DB_HOST, DB_PORT, DB_NAME (also DB_DATABASE), DB_USERNAME, DB_PASSWORD, DB_DRIVER (also DB_CONNECTION)
MailSMTP_HOST, SMTP_PORT
Redis or ValkeyREDIS_HOST, REDIS_PORT, REDIS_PASSWORD
OpenTelemetry CollectorOTEL_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_HOSTS is a JSON array of the environment's hosts, not a comma-separated string. WODBY_PRIMARY_HOST and WODBY_PRIMARY_URL are the canonical ones for links generated outside a request.
  • WODBY_APP_SERVICE_NAME is this service's host name inside the environment. Other services reach the application at that name on port 3000.
  • WODBY_ENV_TYPE tells a development environment from a production-like one.

In a development workspace

  • The checkout is mounted at /usr/src/app and served as it is on disk.
  • Workspace setup installs dependencies with workspace-node prepare. The package manager is taken from packageManager in package.json, otherwise from the lockfile: pnpm-lock.yaml means pnpm, yarn.lock means 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 dev script of package.json when there is one, otherwise with start. WORKSPACE_NODE_COMMAND on the service replaces that command.
  • NODE_ENV is always development here, whatever the environment type. PORT is set, to NODE_PORT unless given, and HOST to 0.0.0.0.
  • A saved file is picked up without a restart or a deployment. A dev script is expected to watch the files itself. A start script 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, build and coverage are not watched. A command set with WORKSPACE_NODE_COMMAND is run as it is, without that watcher; WORKSPACE_NODE_WATCH=0 turns the watcher off. For scripts with their own watcher, CHOKIDAR_USEPOLLING, CHOKIDAR_INTERVAL and WATCHPACK_POLLING are set, because a checkout on network storage needs polling. WORKSPACE_POLL_INTERVAL changes the interval, WORKSPACE_POLLING=0 turns 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= -f1 lists the link variables that are present.

Strapi on Wodby

What this service adds to the Node.js service it is based on.

Build and start

The service's Dockerfile copies the build context to /usr/src/app, runs npm run build with NODE_ENV=production and starts the container with npm run start. package.json must define both scripts: strapi build and strapi start, as create-strapi generates them.

  • The Dockerfile does not install dependencies. The pipeline does it before the image is built (wodby ci run -- npm ci), and node_modules is copied with the code. TypeScript may stay in devDependencies.
  • npm run build compiles the TypeScript project to dist and builds the admin panel. Runtime variables of the service, including the secrets and the database URL, are not available to it, and it does not need them.
  • The image build leaves out .git, .env, .tmp, .strapi, dist, build and public/uploads.
  • The application must listen on port 3000. The service sets PORT and HOST; config/server.ts must read them, as the generated file does.
  • Strapi's own GET /_health answers 204 without touching the database. Use it for health checks.
  • The project must use PostgreSQL through the pg package. The stack's PostgreSQL service is required.

Variables the service sets

VariableMeaning
NODE_ENVproduction in every environment type, including dev. The Node.js service's development value for dev is replaced, because the container runs a production build.
HOST, PORT0.0.0.0 and 3000.
STRAPI_TELEMETRY_DISABLEDtrue.
APP_KEYSTwo generated keys separated by a comma, for server.app.keys. Secret.
API_TOKEN_SALTGenerated, for admin.apiToken.salt. Secret.
ADMIN_JWT_SECRETGenerated, for admin.auth.secret. Secret.
TRANSFER_TOKEN_SALTGenerated, for admin.transfer.token.salt. Secret.
JWT_SECRETGenerated, for the Users & Permissions plugin. Secret.
ENCRYPTION_KEYGenerated, for admin.secrets.encryptionKey. Strapi encrypts stored API tokens with it. Secret.

Each secret is generated once per environment and stays the same across deployments. Changing APP_KEYS, ADMIN_JWT_SECRET or JWT_SECRET signs everybody out; changing ENCRYPTION_KEY makes stored API tokens unreadable in the admin panel; changing API_TOKEN_SALT or TRANSFER_TOKEN_SALT invalidates existing tokens of that kind.

Wodby also sets WODBY_PRIMARY_URL. The boilerplate's config/server.ts uses it as Strapi's url, so links in emails are absolute; PUBLIC_URL overrides it.

Linked services

LinkVariables
dbDATABASE_URL: postgresql://user:password@host:port/database, with the user name and password percent-encoded. Secret. The Node.js service's DB_* variables are set too.
sendmailSMTP_HOST and SMTP_PORT, from the Node.js service.
redisREDIS_HOST, REDIS_PORT and REDIS_PASSWORD, from the Node.js service. Strapi does not use Redis by itself.

config/database.ts must use DATABASE_URL as connection.connection.connectionString when it is set and not combine it with the separate variables. The boilerplate's file does this. The in-cluster PostgreSQL service does not use TLS; for a managed server that requires it, set DATABASE_SSL=true and, if needed, DATABASE_SSL_REJECT_UNAUTHORIZED or DATABASE_SSL_CA.

The boilerplate's config/plugins.ts switches Strapi's email provider to @strapi/provider-email-nodemailer only when SMTP_HOST is set. SMTP_FROM sets the sender; it defaults to no-reply@ followed by WODBY_PRIMARY_HOST.

Behind the gateway

Wodby's gateway terminates TLS and forwards X-Forwarded-Proto and X-Forwarded-For. Strapi must trust them: set proxy: { koa: true } in config/server.ts. Without it, Strapi treats every request as plain HTTP: the admin panel's sign-in cookies are not marked Secure, cookies that require HTTPS in production (such as the session of the Users & Permissions plugin's third-party sign-in) cannot be set, and client addresses are the gateway's. The boilerplate also sets proxy.maxIpsCount to 1, so the client address is the one the gateway added to X-Forwarded-For.

With url set from WODBY_PRIMARY_URL, Strapi redirects / to the admin panel on the primary domain. The admin panel itself is built with relative paths and works on every domain of the environment.

Uploaded media

The local upload provider writes files to public/uploads, and Strapi serves them at /uploads/.... The image build replaces public/uploads with a link to /mnt/files, where the service mounts the uploads volume (10 GB by default). The image's entrypoint gives the volume to the node user when the container starts.

  • Do not rely on files committed to public/uploads: the image build leaves them out.
  • The volume is a single ReadWriteOnce disk. The service is not scalable: it runs one pod, and a new pod starts only after the old one has stopped, so a deployment has a short downtime.
  • To keep media elsewhere, use an upload provider for object storage such as @strapi/provider-upload-aws-s3; the volume then stays empty.

In a development workspace

  • The application runs the dev package script, strapi develop. It compiles the TypeScript sources, serves the admin panel through Vite on the same port with hot reloading, and restarts the server when a file in the project changes (outside public, src/admin, dist and node_modules). Strapi's Vite configuration allows every host name, so the environment's domains work without configuration.
  • File watching uses polling: the workspace exports CHOKIDAR_USEPOLLING, which Strapi's file watcher follows.
  • The Content-Type Builder works only here. Content types created in it are written to src/api and src/components; commit them, together with the type definitions Strapi regenerates in types/generated.
  • NODE_ENV is development here, so the admin panel's cookies are not marked secure.
  • A TypeScript error stops the server until the file is fixed; the development server then restarts by itself.
  • Media uploaded in a workspace is written to public/uploads in the checkout, not to the uploads volume.
  • /.strapi/, /dist/, /build/, /.tmp/, /.strapi-updater.json and /public/uploads/ are kept out of Git status, in addition to the Node.js service's paths.
  • The workspace uses the linked PostgreSQL database of its environment.

Обзор

Технический профиль Node.js (Strapi)

Здесь перечислены версии, которые можно выбрать для Node.js (Strapi) в стеке или окружении. Сам сервис публикуется ревизиями, и стек ссылается на конкретную ревизию.

Тип сервиса

Сервис приложения

Версии

26, 24, 22

Постоянные тома

Uploads

Стеки

Стеки, в которые входит Node.js (Strapi)

Node.js (Strapi) входит в этот публичный стек. Можно создать приложение из публичного стека как есть или добавить сервис в собственный стек.

CI/CD

Сборка Node.js (Strapi) из Git-репозитория

Начните с публичного шаблона проекта или подключите собственный репозиторий. В StackMaster CI push в ветку, за которой следит окружение, запускает сборку Node.js (Strapi), а пайплайн её развёртывает.

Strapi Boilerplate

Используйте его как есть или клонируйте в свой Git-аккаунт.

wodby/strapi-boilerplate

Git-провайдеры

Репозиторий подключается через интеграцию с его Git-провайдером.

CI-провайдеры

StackMaster CI встроен в платформу: пайплайн описывается в файле .wodby/pipeline.yml в репозитории. Для подключённого репозитория те же шаги может выполнять внешний CI-провайдер с помощью StackMaster CLI.

Реестры контейнеров

Собранные образы по умолчанию попадают в StackMaster Registry или во внешний реестр, подключённый как интеграция.

Переменные окружения из интеграций

Интеграция с переменными один раз сохраняет учётные данные стороннего сервиса. Подключите её к Node.js (Strapi), и StackMaster передаст их в контейнер как переменные окружения во время работы, а не при сборке образа.

Конфигурация

Конфигурация сервиса Node.js (Strapi)

Сервис Node.js (Strapi) объявляет следующее. Если значение можно изменить, его задаёт стек, а каждое окружение может его переопределить.

Технические домены

StackMaster выдаёт каждому публичному HTTP-порту технический домен с TLS-сертификатом и продлевает сертификат. Порт, который сервис помечает как частный, домен не получает. Можно добавить собственные домены.

Тома

Uploads

Связи сервиса

Каждая связь — это подключение Node.js (Strapi) к другому сервису. На какой сервис указывает связь, задаёт стек. На карточках перечислены публичные сервисы, которые подходят для каждой связи.

sendmail

Сервисы, которые подходят для этой связи

redis

Сервисы, которые подходят для этой связи