mirror of
https://mirror.suhoan.cn/https://github.com/EasyTier/EasyTier.git
synced 2025-12-14 05:37:23 +08:00
Supports customizing the API server address of the Web frontend through the --api-host parameter (#913)
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
const defaultApiHost = 'https://config-server.easytier.cn';
|
||||
|
||||
interface ApiHost {
|
||||
value: string;
|
||||
usedAt: number;
|
||||
}
|
||||
|
||||
let apiMeta: {
|
||||
api_host: string;
|
||||
} | undefined = (window as any).apiMeta;
|
||||
|
||||
// remove trailing slashes from the URL
|
||||
const cleanUrl = (url: string) => url.replace(/\/+$/, '');
|
||||
|
||||
const defaultApiHost = cleanUrl(apiMeta?.api_host ?? `${location.origin}${location.pathname}`);
|
||||
|
||||
const isValidHttpUrl = (s: string): boolean => {
|
||||
let url;
|
||||
|
||||
@@ -45,7 +52,7 @@ const saveApiHost = (host: string) => {
|
||||
}
|
||||
|
||||
let hosts = cleanAndLoadApiHosts();
|
||||
const newHost: ApiHost = {value: host, usedAt: Date.now()};
|
||||
const newHost: ApiHost = { value: host, usedAt: Date.now() };
|
||||
hosts = hosts.filter((h) => h.value !== host);
|
||||
hosts.push(newHost);
|
||||
localStorage.setItem('apiHosts', JSON.stringify(hosts));
|
||||
@@ -61,4 +68,4 @@ const getInitialApiHost = (): string => {
|
||||
}
|
||||
};
|
||||
|
||||
export {getInitialApiHost, cleanAndLoadApiHosts, saveApiHost}
|
||||
export { getInitialApiHost, cleanAndLoadApiHosts, saveApiHost }
|
||||
Reference in New Issue
Block a user