Тип сервиса
Сервис Node.js (Astro)
Среда выполнения Node.js для сборки сайтов Astro и приложений с серверным рендерингом из исходного кода, с рабочим пространством разработки.
Этот сервис запускает ваш код: его образ собирается из Git-репозитория, а каждая сборка развёртывается в окружение.
В StackMaster
Как Node.js (Astro) работает в 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.
Astro 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 and starts the container with npm run start. package.json must define both scripts.
- The supported production output is the standalone server of the
@astrojs/nodeadapter:adapter: node({ mode: 'standalone' })inastro.config.mjs,astro build, andnode ./dist/server/entry.mjsas the start script. The standalone server renders on-demand pages and serves prerendered pages,public/files and built assets fromdist/client. Static output without an adapter has no server to start, andmode: 'middleware'needs a server of its own. - Astro 7 needs Node.js 22.23.4 or later. All Node.js versions of the service meet it.
- Pages are prerendered at build time unless they set
export const prerender = falseor the configuration setsoutput: 'server'. Endpoints, Actions submitted by forms, and pages that read request data, cookies or runtime variables must be rendered on demand. - 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. Build tools such as@astrojs/checkand TypeScript may stay indevDependencies. npm run buildruns while the image is built. Runtime variables of the service, including the link variables and secrets, are not available to it. Prerendered pages are built without them.- The image build leaves out
.git,.gitignore,.dockerignore,.wodby-ci-cache,distand.astro. - The standalone server has no handler for
SIGTERM: the process ends at once when the container is stopped, and requests in progress are cut off.
Variables the service sets
| Variable | Meaning |
|---|---|
HOST | 0.0.0.0. The standalone server listens on it; without it, it listens on localhost only and the gateway cannot reach it. |
PORT | 3000, the port of the service's endpoint. The standalone server reads it at startup; it takes precedence over server.port of the configuration. |
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. |
WORKSPACE_NODE_COMMAND | exec node node_modules/astro/bin/astro.mjs dev --host "$HOST" --port "$PORT", the start command of a development workspace. |
Runtime variables
- Read runtime variables on the server when a request is handled: with
process.env, or withastro:envfields declared withcontext: 'server'andaccess: 'secret'and imported fromastro:env/server. Secrets are validated when the module is first imported at runtime, not during the build, unlessenv.validateSecretsistrue. import.meta.envandastro:envfields withaccess: 'public'are replaced with their build-time values. They cannot hold runtime variables or secrets. OnlyPUBLIC_variables andcontext: 'client'fields reach the browser.astro.config.mjsis evaluated during the build and in the development server. It readsprocess.env, notastro:env.
Linked services
The service adds no link variables. The database, mail and Redis or Valkey variables of the Node.js service apply unchanged. On-demand pages, endpoints, Actions and middleware read them at request time. They do not reach the browser.
The adapter's default session storage is the container's file system (node_modules/.astro/sessions). It is lost on every deployment and not shared between replicas. Configure a Redis session driver with the Redis or Valkey link before using Astro.session.
Domains, forwarded headers and form submissions
- The gateway terminates TLS, keeps the original
Hostheader and setsX-Forwarded-Proto. Astro usesHost,X-Forwarded-Proto,X-Forwarded-HostandX-Forwarded-Foronly for domains matched bysecurity.allowedDomains. Without a match,Astro.urlandAstro.request.urlarehttp://localhost:3000/.... - The domains are in
WODBY_HOSTSat runtime but not during the build, wheresecurity.allowedDomainsis compiled in. The boilerplate setsallowedDomains: [{}](every domain) and rejects, insrc/middleware.ts, any request whoseX-Forwarded-Hostis not one ofWODBY_HOSTS. Keep both together:[{}]alone lets a client choose the host ofAstro.urlwithX-Forwarded-Host. - With that configuration,
Astro.clientAddressis the firstX-Forwarded-Forvalue, which the client can set. Do not use it for access control. security.checkOriginis on by default: form-encodedPOST,PUT,PATCHandDELETErequests to on-demand routes and Actions are rejected with 403 whenSec-Fetch-Siteis anything butsame-originornone, or, without it, whenOrigindiffers from the origin ofAstro.url. That comparison needs the forwardedhttpsprotocol and host above.
In a development workspace
- The application is started with
astro devfromnode_modules, not through thedevscript ofpackage.json. Options in that script do not apply.astromust be a dependency of the project. - The development server listens on
0.0.0.0:3000. The command line sets both;server.hostandserver.portof the configuration do not apply. - The development server rejects requests for host names it does not know. Add the environment's hosts to
server.allowedHostsinastro.config.mjs:WODBY_HOSTSholds them as a JSON array, andWODBY_APP_SERVICE_NAMEis the internal name. The boilerplate'sastro.config.mjsdoes this. - File watching uses polling: Vite's watcher reads
CHOKIDAR_USEPOLLINGandCHOKIDAR_INTERVAL, which the workspace sets. Saved files are picked up within seconds; new files are picked up once the storage reports the directory change, which can take longer. No configuration change is needed. NODE_ENVisdevelopmenthere./dist/and/.astro/are kept out of Git status, in addition to the Node.js service's paths. Astro's build cache is innode_modules/.astro.- The image build's
npm run builddoes not run in a workspace.
Обзор
Технический профиль Node.js (Astro)
Версии
Основан на
Репозиторий исходного кода
Публичный Helm-чарт
Стеки
Стеки, в которые входит Node.js (Astro)
CI/CD
Сборка Node.js (Astro) из Git-репозитория
Astro Boilerplate
Используйте его как есть или клонируйте в свой Git-аккаунт.
wodby/astro-boilerplateCI-провайдеры
StackMaster CI встроен в платформу: пайплайн описывается в файле .wodby/pipeline.yml в репозитории. Для подключённого репозитория те же шаги может выполнять внешний CI-провайдер с помощью StackMaster CLI.
Реестры контейнеров
Собранные образы по умолчанию попадают в StackMaster Registry или во внешний реестр, подключённый как интеграция.
Переменные окружения из интеграций
Интеграция с переменными один раз сохраняет учётные данные стороннего сервиса. Подключите её к Node.js (Astro), и StackMaster передаст их в контейнер как переменные окружения во время работы, а не при сборке образа.
Конфигурация
Конфигурация сервиса Node.js (Astro)
Технические домены
Связи сервиса
Каждая связь — это подключение Node.js (Astro) к другому сервису. На какой сервис указывает связь, задаёт стек. На карточках перечислены публичные сервисы, которые подходят для каждой связи.
db
Сервисы, которые подходят для этой связи
sendmail
Сервисы, которые подходят для этой связи
redis
Сервисы, которые подходят для этой связи
otel
Сервисы, которые подходят для этой связи