diff --git a/.changeset/violet-buckets-repeat.md b/.changeset/violet-buckets-repeat.md new file mode 100644 index 000000000000..ed68113e155b --- /dev/null +++ b/.changeset/violet-buckets-repeat.md @@ -0,0 +1,5 @@ +--- +'@astrojs/node': minor +--- + +Allow HOST env variable to be provided at runtime diff --git a/packages/integrations/node/README.md b/packages/integrations/node/README.md index be22cee8c46c..e0c8ea67f5e5 100644 --- a/packages/integrations/node/README.md +++ b/packages/integrations/node/README.md @@ -109,6 +109,15 @@ node ./dist/server/entry.mjs For standalone mode the server handles file servering in addition to the page and API routes. + +#### Custom host and port + +You can override the host and port the standalone server runs on by passing them as environment variables at runtime: + +```shell +HOST=0.0.0.0 PORT=3000 node ./dist/server/entry.mjs +``` + #### HTTPS By default the standalone server uses HTTP. This works well if you have a proxy server in front of it that does HTTPS. If you need the standalone server to run HTTPS itself you need to provide your SSL key and certificate. diff --git a/packages/integrations/node/src/standalone.ts b/packages/integrations/node/src/standalone.ts index 5ec2455eeb7a..1a5ab399e317 100644 --- a/packages/integrations/node/src/standalone.ts +++ b/packages/integrations/node/src/standalone.ts @@ -39,7 +39,8 @@ export default function startServer(app: NodeApp, options: Options) { const { client } = resolvePaths(options); const handler = middleware(app); - const host = getResolvedHostForHttpServer(options.host); + // Allow to provide host value at runtime + const host = getResolvedHostForHttpServer(process.env.HOST !== undefined && process.env.HOST !== '' ? process.env.HOST : options.host); const server = createServer( { client,