Skip to content

fix: treat empty port and app id environment variables as unset - #957

Open
rida-ghreizy wants to merge 1 commit into
dapr:mainfrom
rida-ghreizy:fix/settings-empty-env
Open

rida-ghreizy wants to merge 1 commit into
dapr:mainfrom
rida-ghreizy:fix/settings-empty-env

Conversation

@rida-ghreizy

Copy link
Copy Markdown

Description

Settings (src/utils/Settings.util.ts) reads the sidecar and app settings from the environment. DAPR_API_TOKEN, DAPR_HTTP_ENDPOINT and DAPR_GRPC_ENDPOINT use ||, so an empty variable falls back to the default. APP_ID, DAPR_HTTP_PORT, DAPR_GRPC_PORT and APP_PORT use ??, so an empty variable is used as is.

Empty variables are common: DAPR_HTTP_PORT= in a .env file, or - DAPR_HTTP_PORT=${DAPR_HTTP_PORT} in docker-compose when the host variable isn't set. With ??:

Variable set to "" Before After
DAPR_HTTP_PORT "", so the HTTP client builds 127.0.0.1: without a port 3500
DAPR_GRPC_PORT "" 50001
APP_PORT "", so the server listens on an empty port 3000 / 50000
APP_ID "" my-dapr-app

This PR switches these four getters to ||, like the token and endpoint getters. A non-empty value is still used unchanged.

Issue reference

No issue was filed; the problem is described above.

Checklist

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

test/unit/utils/Settings.util.test.ts has new cases that set the four variables to "" (and restore them afterwards) and check the defaults, plus one case showing that a set value still wins. Without the change, 3 of them fail. With it, all 8 tests in the file pass. ESLint and Prettier are clean.

APP_ID, DAPR_HTTP_PORT, DAPR_GRPC_PORT and APP_PORT were read with ??,
so an empty variable (common in .env and docker-compose files) gave an
empty port or app id instead of the default. Use || like the token and
endpoint settings, and add tests.

Signed-off-by: rida <ghreizyrida1@gmail.com>
@rida-ghreizy
rida-ghreizy requested review from a team as code owners November 27, 2026 06:46

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant