vmui: fix trailing slash in serverURL (#5271)

* vmui: add function to autoremove slash at the end of serverURL (#5203)

* vmui: change removeTrailingSlash func
This commit is contained in:
Yury Molodov 2023-11-14 01:21:16 +01:00 committed by GitHub
parent 12aefa8a4b
commit 0e056ddb2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View file

@ -3,6 +3,7 @@ import { getQueryStringValue } from "../../utils/query-string";
import { getFromStorage, saveToStorage } from "../../utils/storage";
import { Theme } from "../../types";
import { isDarkTheme } from "../../utils/theme";
import { removeTrailingSlash } from "../../utils/url";
export interface AppState {
serverUrl: string;
@ -20,7 +21,7 @@ export type Action =
const tenantId = getQueryStringValue("g0.tenantID", "") as string;
export const initialState: AppState = {
serverUrl: getDefaultServer(tenantId),
serverUrl: removeTrailingSlash(getDefaultServer(tenantId)),
tenantId,
theme: (getFromStorage("THEME") || Theme.system) as Theme,
isDarkTheme: null
@ -31,7 +32,7 @@ export function reducer(state: AppState, action: Action): AppState {
case "SET_SERVER":
return {
...state,
serverUrl: action.payload
serverUrl: removeTrailingSlash(action.payload)
};
case "SET_TENANT_ID":
return {

View file

@ -8,4 +8,6 @@ export const isValidHttpUrl = (str: string): boolean => {
}
return url.protocol === "http:" || url.protocol === "https:";
};
};
export const removeTrailingSlash = (url: string) => url.replace(/\/$/, "");