Skip to content

Commit a1df31c

Browse files
committed
fix: fix trailing slash issues causing 404
1 parent 6429725 commit a1df31c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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 urlToString = (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(urlToString(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(urlToString(url), {
118123
method: 'POST',
119124
headers: {
120125
'Content-Type': 'application/json',

0 commit comments

Comments
 (0)