Skip to content

Commit

Permalink
feat: provide HOST env variable at runtime (#5421)
Browse files Browse the repository at this point in the history
* feat: provide HOST env variable at runtime

* doc: add change to documentation

* Update documentation according to suggestions

Co-authored-by: Chris Swithinbank <[email protected]>

* fix: empty string is considered as undefined

Co-authored-by: Chris Swithinbank <[email protected]>
  • Loading branch information
Scttpr and delucis authored Nov 17, 2022
1 parent ff35b47 commit 12236db
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/violet-buckets-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/node': minor
---

Allow HOST env variable to be provided at runtime
9 changes: 9 additions & 0 deletions packages/integrations/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion packages/integrations/node/src/standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 12236db

Please sign in to comment.