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 Aliaksandr Valialkin
parent fbb572a180
commit 33e65e2cab
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1
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 { getFromStorage, saveToStorage } from "../../utils/storage";
import { Theme } from "../../types"; import { Theme } from "../../types";
import { isDarkTheme } from "../../utils/theme"; import { isDarkTheme } from "../../utils/theme";
import { removeTrailingSlash } from "../../utils/url";
export interface AppState { export interface AppState {
serverUrl: string; serverUrl: string;
@ -20,7 +21,7 @@ export type Action =
const tenantId = getQueryStringValue("g0.tenantID", "") as string; const tenantId = getQueryStringValue("g0.tenantID", "") as string;
export const initialState: AppState = { export const initialState: AppState = {
serverUrl: getDefaultServer(tenantId), serverUrl: removeTrailingSlash(getDefaultServer(tenantId)),
tenantId, tenantId,
theme: (getFromStorage("THEME") || Theme.system) as Theme, theme: (getFromStorage("THEME") || Theme.system) as Theme,
isDarkTheme: null isDarkTheme: null
@ -31,7 +32,7 @@ export function reducer(state: AppState, action: Action): AppState {
case "SET_SERVER": case "SET_SERVER":
return { return {
...state, ...state,
serverUrl: action.payload serverUrl: removeTrailingSlash(action.payload)
}; };
case "SET_TENANT_ID": case "SET_TENANT_ID":
return { return {

View File

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