From cc09ae2cdfa599923fbd784d37597cfdee5b6efa Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Mon, 4 Dec 2023 16:37:02 +0100 Subject: [PATCH 1/4] fix: #8681 add env variable port support --- packages/docusaurus/src/server/getHostPort.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus/src/server/getHostPort.ts b/packages/docusaurus/src/server/getHostPort.ts index 4ae80708704f..21f0f7c93b0a 100644 --- a/packages/docusaurus/src/server/getHostPort.ts +++ b/packages/docusaurus/src/server/getHostPort.ts @@ -98,6 +98,9 @@ export async function getHostPort(options: HostPortOptions): Promise<{ }> { const host = options.host ?? 'localhost'; const basePort = options.port ? parseInt(options.port, 10) : DEFAULT_PORT; - const port = await choosePort(host, basePort); + const port = process.env.PORT + ? await choosePort(host, parseInt(process.env.PORT, 10)) + : await choosePort(host, basePort); + return {host, port}; } From 47de8002c2b9e67408dad7f84f9077697f6feddc Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Tue, 5 Dec 2023 17:13:41 +0100 Subject: [PATCH 2/4] fix: review requested changes --- packages/docusaurus-utils/src/constants.ts | 2 +- packages/docusaurus/src/server/getHostPort.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus-utils/src/constants.ts b/packages/docusaurus-utils/src/constants.ts index 6ecba7aea0f5..1d5f4ccf1033 100644 --- a/packages/docusaurus-utils/src/constants.ts +++ b/packages/docusaurus-utils/src/constants.ts @@ -83,7 +83,7 @@ export const DEFAULT_I18N_DIR_NAME = 'i18n'; export const CODE_TRANSLATIONS_FILE_NAME = 'code.json'; /** Dev server opens on this port by default. */ -export const DEFAULT_PORT = 3000; +export const DEFAULT_PORT = parseInt(process.env.PORT || '3000', 10); /** Default plugin ID. */ export const DEFAULT_PLUGIN_ID = 'default'; diff --git a/packages/docusaurus/src/server/getHostPort.ts b/packages/docusaurus/src/server/getHostPort.ts index 21f0f7c93b0a..d78399d6ee9b 100644 --- a/packages/docusaurus/src/server/getHostPort.ts +++ b/packages/docusaurus/src/server/getHostPort.ts @@ -98,9 +98,7 @@ export async function getHostPort(options: HostPortOptions): Promise<{ }> { const host = options.host ?? 'localhost'; const basePort = options.port ? parseInt(options.port, 10) : DEFAULT_PORT; - const port = process.env.PORT - ? await choosePort(host, parseInt(process.env.PORT, 10)) - : await choosePort(host, basePort); + const port = await choosePort(host, basePort); return {host, port}; } From 7cfbec4e32f6af78d9c8d08b5667add06c925371 Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Tue, 5 Dec 2023 17:47:33 +0100 Subject: [PATCH 3/4] wip: refactor --- packages/docusaurus-utils/src/constants.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-utils/src/constants.ts b/packages/docusaurus-utils/src/constants.ts index 1d5f4ccf1033..5039d6989b00 100644 --- a/packages/docusaurus-utils/src/constants.ts +++ b/packages/docusaurus-utils/src/constants.ts @@ -83,7 +83,9 @@ export const DEFAULT_I18N_DIR_NAME = 'i18n'; export const CODE_TRANSLATIONS_FILE_NAME = 'code.json'; /** Dev server opens on this port by default. */ -export const DEFAULT_PORT = parseInt(process.env.PORT || '3000', 10); +export const DEFAULT_PORT = process.env.PORT + ? parseInt(process.env.PORT, 10) + : 3000; /** Default plugin ID. */ export const DEFAULT_PLUGIN_ID = 'default'; From 3c4918f7aa45b8a9b9eaa7d070db3439071a3101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Thu, 7 Dec 2023 11:29:27 +0100 Subject: [PATCH 4/4] Update packages/docusaurus/src/server/getHostPort.ts --- packages/docusaurus/src/server/getHostPort.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/docusaurus/src/server/getHostPort.ts b/packages/docusaurus/src/server/getHostPort.ts index d78399d6ee9b..4ae80708704f 100644 --- a/packages/docusaurus/src/server/getHostPort.ts +++ b/packages/docusaurus/src/server/getHostPort.ts @@ -99,6 +99,5 @@ export async function getHostPort(options: HostPortOptions): Promise<{ const host = options.host ?? 'localhost'; const basePort = options.port ? parseInt(options.port, 10) : DEFAULT_PORT; const port = await choosePort(host, basePort); - return {host, port}; }