refactor: Naming-Konventionen für digitaleEingaenge umgesetzt
- digitaleEingaengeMockData.js = strukturierte Datenbasis für Development - digitaleEingaengeAPIHandler.ts = API-Endpunkt zur Auslieferung im Dev - fetchDigitaleEingaengeService.ts = Service zur Umwandlung von window-Variablen - Naming-Schema sorgt für klare Struktur und gute Lernbarkeit
This commit is contained in:
26
services/fetchLast20MessagesService.ts
Normal file
26
services/fetchLast20MessagesService.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
// /services/fetchLast20MessagesService.ts
|
||||
|
||||
export const fetchLast20MessagesFromWindow = async (): Promise<
|
||||
string | null
|
||||
> => {
|
||||
if (typeof window === "undefined") return null;
|
||||
|
||||
const isDev = process.env.NEXT_PUBLIC_NODE_ENV === "development";
|
||||
|
||||
const scriptSrc = isDev
|
||||
? "/api/cpl/last20Messages" // in Dev → per API geladen
|
||||
: "/CPL?/CPL/SERVICE/Start.js"; // in Prod → echtes Script vom CPL
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const script = document.createElement("script");
|
||||
script.src = scriptSrc;
|
||||
script.async = true;
|
||||
script.onload = () => resolve();
|
||||
script.onerror = () => reject("❌ Fehler beim Laden von Start.js");
|
||||
document.body.appendChild(script);
|
||||
});
|
||||
|
||||
const raw = (window as any).win_last20Messages;
|
||||
|
||||
return raw ? String(raw) : null;
|
||||
};
|
||||
Reference in New Issue
Block a user