File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
265265const LOCAL_STORAGE_KEY_V1 = "pd.devtool.endpoint" ;
266266const 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
269271export 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/**
Original file line number Diff line number Diff 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 ( ) ;
You can’t perform that action at this time.
0 commit comments