Skip to content

Commit e84f708

Browse files
authored
feat: clean backend endpoint input (#159)
1 parent 30b3371 commit e84f708

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

webapp/_webapp/src/libs/apiclient.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ApiClient {
4444
}
4545

4646
updateBaseURL(baseURL: string, apiVersion: ApiVersion): void {
47-
this.axiosInstance.defaults.baseURL = `${baseURL}/_pd/api/${apiVersion}`;
47+
this.axiosInstance.defaults.baseURL = `${sanitizeEndpoint(baseURL)}/_pd/api/${apiVersion}`;
4848
switch (apiVersion) {
4949
case "v1":
5050
storage.setItem(API_VERSION_STORAGE_KEYS.v1, this.axiosInstance.defaults.baseURL);
@@ -265,6 +265,8 @@ const DEFAULT_ENDPOINT = `${process.env.PD_API_ENDPOINT || "http://localhost:300
265265
const LOCAL_STORAGE_KEY_V1 = "pd.devtool.endpoint";
266266
const LOCAL_STORAGE_KEY_V2 = "pd.devtool.endpoint.v2";
267267

268+
const sanitizeEndpoint = (url: string) => url.trim().replace(/\/+$/, "");
269+
268270
// Create apiclient instance with endpoint from storage or default
269271
export const getEndpointFromStorage = () => {
270272
let endpoint = "";
@@ -275,7 +277,7 @@ export const getEndpointFromStorage = () => {
275277
endpoint = DEFAULT_ENDPOINT;
276278
}
277279

278-
return endpoint.replace("/_pd/api/v1", "").replace("/_pd/api/v2", ""); // compatible with old endpoint
280+
return sanitizeEndpoint(endpoint.replace("/_pd/api/v1", "").replace("/_pd/api/v2", "")); // compatible with old endpoint
279281
};
280282

281283
/**

0 commit comments

Comments
 (0)