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:
- Set COUCH_URL to a URL with a non-5988 port:
export COUCH_URL=http://medic:password@localhost:61418/medic
- Run any cht-conf command with --local:
npx cht --local compile-app-settings upload-app-settings
- 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}`;
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:
export COUCH_URL=http://medic:password@localhost:61418/medic
npx cht --local compile-app-settings upload-app-settings
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_URLincludes a port, --local should use that port. Port 5988 should only be the fallback when no port is specified.Logs
Suggested fix