summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/violet-buckets-repeat.md5
-rw-r--r--packages/integrations/node/README.md9
-rw-r--r--packages/integrations/node/src/standalone.ts3
3 files changed, 16 insertions, 1 deletions
diff --git a/.changeset/violet-buckets-repeat.md b/.changeset/violet-buckets-repeat.md
new file mode 100644
index 000000000..ed68113e1
--- /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 be22cee8c..e0c8ea67f 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 5ec2455ee..1a5ab399e 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,