This commit is contained in:
wushumin
2026-05-11 15:28:27 +08:00
commit 9aac78b8da
289 changed files with 67193 additions and 0 deletions

24
user-app/src/utils/env.ts Normal file
View File

@@ -0,0 +1,24 @@
const LOCAL_API_BASE_URL = "http://127.0.0.1:8787";
function isLocalLikeHostname(hostname: string) {
return (
hostname === "localhost" ||
hostname === "127.0.0.1" ||
hostname === "0.0.0.0" ||
/^10\./.test(hostname) ||
/^192\.168\./.test(hostname) ||
/^172\.(1[6-9]|2\d|3[0-1])\./.test(hostname)
);
}
export function resolveApiBaseUrl() {
if (import.meta.env.DEV) {
return LOCAL_API_BASE_URL;
}
if (typeof window !== "undefined" && isLocalLikeHostname(window.location.hostname)) {
return LOCAL_API_BASE_URL;
}
return import.meta.env.VITE_API_BASE_URL || LOCAL_API_BASE_URL;
}