Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow Connector's addresses to be relative URLs #241

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/facades/management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export class ManagementController extends EdcController {
return new DataplaneController(this.inner, this.context);
}
get edrs(): EdrController {
return new EdrController(this.#inner, this.#context);
return new EdrController(this.inner, this.context);
}
get secrets(): SecretController {
return new SecretController(this.#inner, this.#context);
return new SecretController(this.inner, this.context);
}
get policyDefinitions() {
return new PolicyDefinitionController(this.inner, this.context);
Expand Down
7 changes: 4 additions & 3 deletions src/inner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ export class Inner {
}

async #fetch(baseUrl: string, innerRequest: InnerRequest): Promise<Response> {
const url = new URL(`${baseUrl}${innerRequest.path}`);

const searchParams = new URLSearchParams();
if (innerRequest.query) {
Object.entries(innerRequest.query).forEach(([key, value]) => {
url.searchParams.append(key, value);
searchParams.append(key, value);
});
}

const url = `${baseUrl}${innerRequest.path}?${searchParams.toString()}`;

const method = innerRequest.method;
const request = new Request(url, {
method,
Expand Down
13 changes: 13 additions & 0 deletions tests/edc-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,17 @@ describe("EdcConnectorClient", () => {
});
});
});

describe("edcClient.inner.#fetch", () => {
it("accepts relative urls", async () => {
const edcClient = new EdcConnectorClient.Builder()
.apiToken("123456")
.defaultUrl("/defaultUrl")
.build();

await expect(edcClient.observability.checkHealth()).rejects.not.toThrow(
"Invalid URL",
);
});
});
});