Skip to content

Commit

Permalink
Trim trailing slashes on passed API and web URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Sep 24, 2024
1 parent b6f1e97 commit adc53df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,14 @@ export class Client {

this.tracingSampleRate = getTracingSamplingRate();
this.apiUrl = trimQuotes(config.apiUrl ?? defaultConfig.apiUrl) ?? "";
if (this.apiUrl.endsWith("/")) {
this.apiUrl = this.apiUrl.slice(0, -1);
}
this.apiKey = trimQuotes(config.apiKey ?? defaultConfig.apiKey);
this.webUrl = trimQuotes(config.webUrl ?? defaultConfig.webUrl);
if (this.webUrl?.endsWith("/")) {
this.webUrl = this.webUrl.slice(0, -1);
}
this.timeout_ms = config.timeout_ms ?? 12_000;
this.caller = new AsyncCaller(config.callerOptions ?? {});
this.batchIngestCaller = new AsyncCaller({
Expand Down
12 changes: 12 additions & 0 deletions js/src/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ describe("Client", () => {
});
});

it("should trim trailing slash on a passed apiUrl", () => {
const client = new Client({ apiUrl: "https://example.com/" });
const result = (client as any).apiUrl;
expect(result).toBe("https://example.com");
});

describe("getHostUrl", () => {
it("should return the webUrl if it exists", () => {
const client = new Client({
Expand All @@ -110,6 +116,12 @@ describe("Client", () => {
expect(result).toBe("https://example.com");
});

it("should trim trailing slash on a passed webUrl", () => {
const client = new Client({ webUrl: "https://example.com/" });
const result = (client as any).getHostUrl();
expect(result).toBe("https://example.com");
});

it("should return 'https://dev.smith.langchain.com' if apiUrl contains 'dev'", () => {
const client = new Client({
apiUrl: "https://dev.smith.langchain.com/api",
Expand Down

0 comments on commit adc53df

Please sign in to comment.