Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: provide HOST env variable at runtime #5421

Merged
merged 4 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 10 additions & 0 deletions packages/integrations/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ node ./dist/server/entry.mjs

For standalone mode the server handles file servering in addition to the page and API routes.


#### Runtime HOST and PORT

It is possible to override built HOST and PORT values with [runtime environment variables](https://docs.astro.
build/en/guides/environment-variables/#using-the-cli)
Scttpr marked this conversation as resolved.
Show resolved Hide resolved

```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 : options.host);
Scttpr marked this conversation as resolved.
Show resolved Hide resolved
const server = createServer(
{
client,
Expand Down