IP kommt von window und nicht von.env.local, weil in CHIPTOOL kann die IP eingestellt werden

This commit is contained in:
ISA
2024-10-21 12:25:16 +02:00
parent 328b1d8a0e
commit 6f26e1b503
5 changed files with 111 additions and 72 deletions

View File

@@ -14,7 +14,8 @@ import { Icon } from "@iconify/react";
function Dashboard() {
//const apiUrl = process.env.NEXT_PUBLIC_API_BASE_URL;
const apiUrl = `https://${window.ip}:443`;
const [isClient, setIsClient] = useState(false);
const [last20Messages, setLast20Messages] = useState([]);
const [kueOnline, setkueOnline] = useState([]);
const [ip, setIp] = useState("");
@@ -24,28 +25,42 @@ function Dashboard() {
const [error, setError] = useState(null);
const [kueCableBreak, setKueCableBreak] = useState([]);
const [appVersion, setAppVersion] = useState("");
const [apiUrl, setApiUrl] = useState("");
/* useEffect(() => {
setIsClient(true);
if (typeof window !== "undefined") {
setApiUrl(`https://${window.ip}:443`);
}
}, []); */
/* if (!isClient) {
return null; // or a loading spinner
} */
//const apiUrl = `https://${ip}:443`;
useEffect(() => {
loadWindowVariables(apiUrl)
.then(() => {
if (window.last20Messages) {
const parsedMessages = parseMessages(window.last20Messages);
setLast20Messages(parsedMessages);
setIp(window.ip);
setSubnet(window.subnet);
setGateway(window.gateway);
setAppVersion(window.appVersion);
} else {
console.error("Konnte last20Messages nicht finden.");
setError("Konnte last20Messages nicht finden.");
}
setLoading(false);
})
.catch((error) => {
console.error("Fehler beim Laden des Skripts:", error);
setError(error);
setLoading(false);
});
if (typeof window !== "undefined") {
loadWindowVariables(apiUrl)
.then(() => {
if (window.last20Messages) {
const parsedMessages = parseMessages(window.last20Messages);
setLast20Messages(parsedMessages);
setIp(window.ip);
setSubnet(window.subnet);
setGateway(window.gateway);
setAppVersion(window.appVersion);
setApiUrl(`https://${window.ip}:443`);
} else {
console.error("Konnte last20Messages nicht finden.");
setError("Konnte last20Messages nicht finden.");
}
setLoading(false);
})
.catch((error) => {
console.error("Fehler beim Laden des Skripts:", error);
setError(error);
setLoading(false);
});
}
}, [apiUrl]);
useEffect(() => {
loadWindowVariables(apiUrl)