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>
This commit is contained in:
parent
ff35b4759b
commit
12236dbc06
3 changed files with 16 additions and 1 deletions
5
.changeset/violet-buckets-repeat.md
Normal file
5
.changeset/violet-buckets-repeat.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@astrojs/node': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Allow HOST env variable to be provided at runtime
|
|
@ -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.
|
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
|
#### 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.
|
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.
|
||||||
|
|
|
@ -39,7 +39,8 @@ export default function startServer(app: NodeApp, options: Options) {
|
||||||
const { client } = resolvePaths(options);
|
const { client } = resolvePaths(options);
|
||||||
const handler = middleware(app);
|
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(
|
const server = createServer(
|
||||||
{
|
{
|
||||||
client,
|
client,
|
||||||
|
|
Loading…
Reference in a new issue