Skip to content

--local flag ignores port from COUCH_URL environment variable, always uses 5988 #790

@inromualdo

Description

@inromualdo

Describe the bug
When using --local, cht-conf reads the COUCH_URL environment variable and logs it correctly, but then discards the port and hardcodes 5988. This makes --local unusable when the CHT API is exposed on a different port.

The issue is in src/lib/get-api-url.js line 58 in the parseLocalUrl function:

parsed.host = ${parsed.hostname}:5988;

This overwrites the port from the parsed URL unconditionally.

To Reproduce
Steps to reproduce the behavior:

  1. Set COUCH_URL to a URL with a non-5988 port:
    export COUCH_URL=http://medic:password@localhost:61418/medic
  2. Run any cht-conf command with --local:
    npx cht --local compile-app-settings upload-app-settings
  3. Observe the output — it logs the correct URL but connects to port 5988:
    INFO Using local url from COUCH_URL environment variable: http://medic:****@localhost:61418/medic
    INFO Checking that http://medic:****@localhost:5988/medic/ is available...
    ERROR Failed to get a response from http://medic:****@localhost:5988/medic/

Expected behavior
When COUCH_URL includes a port, --local should use that port. Port 5988 should only be the fallback when no port is specified.

Logs

INFO Using local url from COUCH_URL environment variable: http://medic:****@localhost:61418/medic
  INFO Checking that http://medic:****@localhost:5988/medic/ is available...
  INFO Error: Failed to get a response from http://medic:****@localhost:5988/medic/. Maybe you entered the wrong URL, wrong port or the instance is not started. Please check and try again.
      at Object.available (/Users/romuald/Developer/Medic/demo-config/node_modules/cht-conf/src/lib/api.js:168:13)
      at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
      at async module.exports (/Users/romuald/Developer/Medic/demo-config/node_modules/cht-conf/src/lib/main.js:170:5)
      at async /Users/romuald/Developer/Medic/demo-config/node_modules/cht-conf/src/bin/index.js:16:5

Suggested fix

  // src/lib/get-api-url.js, line 58
  // Before:
  parsed.host = `${parsed.hostname}:5988`;
  // After:
  parsed.host = `${parsed.hostname}:${parsed.port || 5988}`;

Metadata

Metadata

Assignees

Labels

Type: BugFix something that isn't working as intended

Type

Projects

Status

🔍 In Review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions