Skip to content

Commit 8698727

Browse files
authored
fix: fix trailing slash issues causing 404 (#242)
1 parent 6429725 commit 8698727

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk-common",
3-
"version": "4.13.3",
3+
"version": "4.13.4",
44
"description": "Common library for Eppo JavaScript SDKs (web, react native, and node)",
55
"main": "dist/index.js",
66
"files": [

src/http-client.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ export interface IBanditParametersResponse {
4646
bandits: Record<string, BanditParameters>;
4747
}
4848

49+
const urlWithNoTrailingSlash = (url: URL) => {
50+
url.pathname = url.pathname.replace(/\/$/, '');
51+
return url.toString();
52+
};
53+
4954
export interface IHttpClient {
5055
getUniversalFlagConfiguration(): Promise<IUniversalFlagConfigResponse | undefined>;
5156
getBanditParameters(): Promise<IBanditParametersResponse | undefined>;
@@ -89,7 +94,7 @@ export default class FetchHttpClient implements IHttpClient {
8994
const controller = new AbortController();
9095
const signal = controller.signal;
9196
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
92-
const response = await fetch(url.toString(), { signal });
97+
const response = await fetch(urlWithNoTrailingSlash(url), { signal });
9398
// Clear timeout when response is received within the budget.
9499
clearTimeout(timeoutId);
95100

@@ -114,7 +119,7 @@ export default class FetchHttpClient implements IHttpClient {
114119
const signal = controller.signal;
115120
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
116121

117-
const response = await fetch(url.toString(), {
122+
const response = await fetch(urlWithNoTrailingSlash(url), {
118123
method: 'POST',
119124
headers: {
120125
'Content-Type': 'application/json',

0 commit comments

Comments
 (0)