Skip to content

Commit

Permalink
feat: allow Connector's addresses to be relative URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
fdionisi committed Jun 10, 2024
1 parent e923554 commit a816643
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
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",
);
});
});
});

0 comments on commit a816643

Please sign in to comment.