diff --git a/packages/grpc-js/src/call-credentials-filter.ts b/packages/grpc-js/src/call-credentials-filter.ts index a5459b53..5263d97f 100644 --- a/packages/grpc-js/src/call-credentials-filter.ts +++ b/packages/grpc-js/src/call-credentials-filter.ts @@ -39,7 +39,7 @@ export class CallCredentialsFilter extends BaseFilter implements Filter { if (splitPath.length >= 2) { serviceName = splitPath[1]; } - const hostname = splitHostPort(stream.getHost()).host; + const hostname = splitHostPort(stream.getHost())?.host ?? 'localhost'; /* Currently, call credentials are only allowed on HTTPS connections, so we * can assume that the scheme is "https" */ this.serviceUrl = `https://${hostname}/${serviceName}`;