25 lines
625 B
TypeScript
25 lines
625 B
TypeScript
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;
|
|
}
|