Supports customizing the API server address of the Web frontend through the --api-host parameter (#913)

This commit is contained in:
Mg Pig
2025-06-02 06:46:12 +08:00
committed by GitHub
parent 0a38a8ef4a
commit b469f8197a
7 changed files with 150 additions and 55 deletions
+1
View File
@@ -5,6 +5,7 @@
<link rel="icon" type="image/png" href="/easytier.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>EasyTier Dashboard</title>
<script src="/api_meta.js"></script>
</head>
<body>
<div id="app"></div>
+11 -4
View File
@@ -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 }
+11
View File
@@ -3,9 +3,20 @@ import vue from '@vitejs/plugin-vue'
// import { viteSingleFile } from "vite-plugin-singlefile"
const WEB_BASE_URL = process.env.WEB_BASE_URL || '';
const API_BASE_URL = process.env.API_BASE_URL || 'http://localhost:11211';
// https://vite.dev/config/
export default defineConfig({
base: WEB_BASE_URL,
plugins: [vue(),/* viteSingleFile() */],
server: {
proxy: {
"/api": {
target: API_BASE_URL,
},
"/api_meta.js": {
target: API_BASE_URL,
},
}
}
})