From 40b0774ef8bdd8a2c9829572d01f549262ca7c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Thu, 5 Feb 2026 22:56:03 +0000 Subject: [PATCH] feat: add API_HOST env --- apps/api/src/index.ts | 8 +++---- .../self-hosting/environment-variables.mdx | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index 941856d9..b0829c0d 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -63,6 +63,9 @@ declare module 'fastify' { } const port = Number.parseInt(process.env.API_PORT || '3000', 10); +const host = + process.env.API_HOST || + (process.env.NODE_ENV === 'production' ? '0.0.0.0' : 'localhost'); const startServer = async () => { logger.info('Starting server'); @@ -263,10 +266,7 @@ const startServer = async () => { }); } - await fastify.listen({ - host: process.env.NODE_ENV === 'production' ? '0.0.0.0' : 'localhost', - port, - }); + await fastify.listen({ host, port }); try { // Notify when keys expires diff --git a/apps/public/content/docs/self-hosting/environment-variables.mdx b/apps/public/content/docs/self-hosting/environment-variables.mdx index e062c95f..df823f0d 100644 --- a/apps/public/content/docs/self-hosting/environment-variables.mdx +++ b/apps/public/content/docs/self-hosting/environment-variables.mdx @@ -744,6 +744,27 @@ Port for the API service to listen on. API_PORT=3000 ``` +### API_HOST + +**Type**: `string` +**Required**: No +**Default**: `0.0.0.0` (production) / `localhost` (development) + +Host address for the API service to bind to. Set to `::` to enable IPv6 support (useful for platforms like Railway that use IPv6 for internal networking). + +**Example**: +```bash +# Default IPv4 only +API_HOST=0.0.0.0 + +# IPv6 (dual-stack, accepts both IPv4 and IPv6) +API_HOST=:: +``` + + +Use `API_HOST=::` when deploying on platforms like Railway where private networking requires IPv6. The `::` address enables dual-stack mode, accepting both IPv4 and IPv6 connections on most systems. + + ## Logging ### LOG_LEVEL