fix(config): support HOST_PORT as fallback for PORT environment variable

This commit is contained in:
Lucas Winther
2026-09-07 01:16:48 +02:00
parent c9ba15bca0
commit 86c7dadb9b
2 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -69,7 +69,7 @@ export function loadConfig(
readOnlyEnv === "yes"; readOnlyEnv === "yes";
const portArg = parseCliArg(argv, "--port"); const portArg = parseCliArg(argv, "--port");
const portStr = portArg ?? env.PORT; const portStr = portArg ?? env.PORT ?? env.HOST_PORT;
let port: number | undefined; let port: number | undefined;
if (portStr !== undefined && portStr.trim() !== "") { if (portStr !== undefined && portStr.trim() !== "") {
const parsed = parseInt(portStr.trim(), 10); const parsed = parseInt(portStr.trim(), 10);
+12
View File
@@ -82,6 +82,18 @@ describe("Configuration Loader (HTTP & Stdio Support)", () => {
expect(config.apiKey).toBeUndefined(); expect(config.apiKey).toBeUndefined();
}); });
test("loads HTTP configuration when HOST_PORT is set as fallback without PORT", () => {
process.env.OPENPROJECT_BASE_URL = "https://openproject.example.com";
delete process.env.OPENPROJECT_API_KEY;
delete process.env.PORT;
process.env.HOST_PORT = "3000";
const config = loadConfig();
expect(config.baseUrl).toBe("https://openproject.example.com");
expect(config.port).toBe(3000);
expect(config.apiKey).toBeUndefined();
});
test("loads HTTP configuration with API key when provided", () => { test("loads HTTP configuration with API key when provided", () => {
process.env.OPENPROJECT_BASE_URL = "https://openproject.example.com"; process.env.OPENPROJECT_BASE_URL = "https://openproject.example.com";
process.env.OPENPROJECT_API_KEY = "test-key"; process.env.OPENPROJECT_API_KEY = "test-key";