Skip to content

Commit c18ecaf

Browse files
committed
fix: debug mid-url backslash
1 parent dee42b8 commit c18ecaf

2 files changed

Lines changed: 5 additions & 3 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
/**

webapp/_webapp/src/views/settings/sections/user-developer-tools.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const UserDeveloperTools = () => {
4040
label="Backend Endpoint"
4141
description="You need to refresh the page to apply the changes"
4242
value={endpoint}
43-
onChange={(value) => setEndpoint(value.replace(/\s+/g, "").replace(/\/+$/, ""))}
43+
onChange={setEndpoint}
4444
showResetButton={true}
4545
onReset={() => {
4646
resetApiClientEndpoint();

0 commit comments

Comments
 (0)