Skip to content

Commit

Permalink
do not add https:// for fqdns
Browse files Browse the repository at this point in the history
  • Loading branch information
gimmyxd committed Jan 29, 2025
1 parent fa55bef commit f830bc1
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/directory/v3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export enum ImportMsgCase {
RELATION = "relation",
}

const ADDRESS_REGEX = /https?:\/\//;

export class DirectoryV3 {
ReaderClient: Client<typeof Reader>;
WriterClient: Client<typeof Writer>;
Expand Down Expand Up @@ -182,6 +184,13 @@ export class DirectoryV3 {
);
};

const getServiceUrl = (baseServiceUrl: string) => {
const scheme = "https://";

const serviceUrlMath = baseServiceUrl?.match(ADDRESS_REGEX);
return serviceUrlMath ? baseServiceUrl : `${scheme}${baseServiceUrl}`;
};

const createTransport = (
config: ServiceConfig | undefined,
fallback: ServiceConfig | undefined,
Expand Down Expand Up @@ -209,7 +218,9 @@ export class DirectoryV3 {
}
interceptors.push(setCustomHeaders(customHeaders));
return createGrpcTransport({
baseUrl: `https://${serviceUrl || "directory.prod.aserto.com:8443"}`,
baseUrl: getServiceUrl(
serviceUrl || "directory.prod.aserto.com:8443",
),
interceptors: interceptors,
nodeOptions: nodeOptions,
});
Expand All @@ -234,6 +245,7 @@ export class DirectoryV3 {
}

const baseServiceUrl = config.url;

const baseApiKey = config.apiKey;
const baseTenantId = config.tenantId;
const baseCaFile = !!config.caFile
Expand All @@ -252,7 +264,7 @@ export class DirectoryV3 {
const baseGrpcTransport =
!!config.url || (!!config.apiKey && !!config.tenantId)
? createGrpcTransport({
baseUrl: `https://${baseServiceUrl}`,
baseUrl: getServiceUrl(baseServiceUrl!),
interceptors: interceptors,
nodeOptions: baseNodeOptions,
})
Expand Down

0 comments on commit f830bc1

Please sign in to comment.