summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Scttpr <charles.capelli@qonfucius.team> 2022-11-17 16:48:20 +0100
committerGravatar GitHub <noreply@github.com> 2022-11-17 10:48:20 -0500
commit12236dbc06e1e43618b61d180020a67cb31499f8 (patch)
treefd50411be961139665a2c48f07f13b7913b52e0c
parentff35b4759bd0fecfee6c99bf510c2e32d2574992 (diff)
downloadastro-12236dbc06e1e43618b61d180020a67cb31499f8.tar.gz
astro-12236dbc06e1e43618b61d180020a67cb31499f8.tar.zst
astro-12236dbc06e1e43618b61d180020a67cb31499f8.zip
feat: provide HOST env variable at runtime (#5421)
* feat: provide HOST env variable at runtime * doc: add change to documentation * Update documentation according to suggestions Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> * fix: empty string is considered as undefined Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
-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,