diff --git a/src/db/db.ts b/src/db/db.ts index 039077bc..1ae6c61b 100644 --- a/src/db/db.ts +++ b/src/db/db.ts @@ -150,6 +150,8 @@ export class Db extends HierarchicalEmitter { : this.#defaultOpts.dbOptions.keyspace ?? undefined, }; + endpoint = endpoint.endsWith('/') ? endpoint.replace(/\/+$/, "") : endpoint; + this.#httpClient = new DataAPIHttpClient({ baseUrl: endpoint, tokenProvider: this.#defaultOpts.dbOptions.token, diff --git a/tests/unit/db/db.test.ts b/tests/unit/db/db.test.ts index ed1ed0e0..e49bb3d0 100644 --- a/tests/unit/db/db.test.ts +++ b/tests/unit/db/db.test.ts @@ -43,6 +43,11 @@ describe('unit.db.db', () => { const client = new DataAPIClient(); assert.doesNotThrow(() => client.db(TEST_APPLICATION_URI)); }); + + it("should strip trailing slashes from the endpoint", () => { + const db = new Db(internalOps(), "https://id-region.apps.astra.datastax.com/", DbOptsHandler.empty); + assert.strictEqual(db["_httpClient"].baseUrl, `https://id-region.apps.astra.datastax.com/${DEFAULT_DATA_API_PATHS["astra"]}`)); + }); }); describe('new Db tests', () => {