feat(mock): zentrale Mock-API-Struktur eingeführt mit .env-Steuerung
- Mock-API-Endpunkte unter pages/api/mocks/webservice erstellt (JSON-basiert) - Zentrale Variable NEXT_PUBLIC_USE_MOCKS zur Modussteuerung eingeführt - fetchGis*-Services rufen je nach Modus reale oder Mockdaten ab - Alert-Hinweis im UI für aktive Mockumgebung eingebaut - .env.production sichert produktives Verhalten (Mocks deaktiviert) - mockData-Verzeichnis via .gitignore vom Repo ausgeschlossen - appVersion.js auf 1.1.231 erhöht
This commit is contained in:
26
pages/api/mocks/webservice/cablesStatic.js
Normal file
26
pages/api/mocks/webservice/cablesStatic.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
// ⛔ Schutz: API nur im Development-Modus aktiv
|
||||
const filePath = path.join(process.cwd(), "mockData", "CablesStatic.json");
|
||||
|
||||
function devHandler(req, res) {
|
||||
if (req.method === "GET") {
|
||||
try {
|
||||
const data = fs.readFileSync(filePath, "utf-8");
|
||||
res.status(200).json(JSON.parse(data));
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Fehler beim Lesen der CablesStatic.json" });
|
||||
}
|
||||
} else {
|
||||
res.status(405).json({ error: "Methode nicht erlaubt" });
|
||||
}
|
||||
}
|
||||
|
||||
function prodHandler(_, res) {
|
||||
return res.status(404).json({ error: "Mock-API ist nur im Entwicklungsmodus verfügbar." });
|
||||
}
|
||||
|
||||
const handler = process.env.NODE_ENV !== "development" ? prodHandler : devHandler;
|
||||
|
||||
export default handler;
|
||||
17
pages/api/mocks/webservice/getIconsStatic.js
Normal file
17
pages/api/mocks/webservice/getIconsStatic.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const filePath = path.join(process.cwd(), "mockData", "GetIconsStatic.json");
|
||||
|
||||
export default function handler(req, res) {
|
||||
if (req.method === "GET") {
|
||||
try {
|
||||
const data = fs.readFileSync(filePath, "utf-8");
|
||||
res.status(200).json(JSON.parse(data));
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Fehler beim Lesen der GetIconsStatic.json" });
|
||||
}
|
||||
} else {
|
||||
res.status(405).json({ error: "Methode nicht erlaubt" });
|
||||
}
|
||||
}
|
||||
17
pages/api/mocks/webservice/gisLinesStatus.js
Normal file
17
pages/api/mocks/webservice/gisLinesStatus.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const filePath = path.join(process.cwd(), "mockData", "GisLinesStatus.json");
|
||||
|
||||
export default function handler(req, res) {
|
||||
if (req.method === "GET") {
|
||||
try {
|
||||
const data = fs.readFileSync(filePath, "utf-8");
|
||||
res.status(200).json(JSON.parse(data));
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Fehler beim Lesen der GisLinesStatus.json" });
|
||||
}
|
||||
} else {
|
||||
res.status(405).json({ error: "Methode nicht erlaubt" });
|
||||
}
|
||||
}
|
||||
17
pages/api/mocks/webservice/gisStationsMeasurements.js
Normal file
17
pages/api/mocks/webservice/gisStationsMeasurements.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const filePath = path.join(process.cwd(), "mockData", "GisStationsMeasurements.json");
|
||||
|
||||
export default function handler(req, res) {
|
||||
if (req.method === "GET") {
|
||||
try {
|
||||
const data = fs.readFileSync(filePath, "utf-8");
|
||||
res.status(200).json(JSON.parse(data));
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Fehler beim Lesen der GisStationsMeasurements.json" });
|
||||
}
|
||||
} else {
|
||||
res.status(405).json({ error: "Methode nicht erlaubt" });
|
||||
}
|
||||
}
|
||||
17
pages/api/mocks/webservice/gisStationsStaticDistrict.js
Normal file
17
pages/api/mocks/webservice/gisStationsStaticDistrict.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const filePath = path.join(process.cwd(), "mockData", "GisStationsStaticDistrict.json");
|
||||
|
||||
export default function handler(req, res) {
|
||||
if (req.method === "GET") {
|
||||
try {
|
||||
const data = fs.readFileSync(filePath, "utf-8");
|
||||
res.status(200).json(JSON.parse(data));
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Fehler beim Lesen der GisStationsStaticDistrict.json" });
|
||||
}
|
||||
} else {
|
||||
res.status(405).json({ error: "Methode nicht erlaubt" });
|
||||
}
|
||||
}
|
||||
17
pages/api/mocks/webservice/gisStationsStatusDistrict.js
Normal file
17
pages/api/mocks/webservice/gisStationsStatusDistrict.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const filePath = path.join(process.cwd(), "mockData", "GisStationsStatusDistrict.json");
|
||||
|
||||
export default function handler(req, res) {
|
||||
if (req.method === "GET") {
|
||||
try {
|
||||
const data = fs.readFileSync(filePath, "utf-8");
|
||||
res.status(200).json(JSON.parse(data));
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Fehler beim Lesen der GisStationsStatusDistrict.json" });
|
||||
}
|
||||
} else {
|
||||
res.status(405).json({ error: "Methode nicht erlaubt" });
|
||||
}
|
||||
}
|
||||
17
pages/api/mocks/webservice/gisSystemStatic.js
Normal file
17
pages/api/mocks/webservice/gisSystemStatic.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const filePath = path.join(process.cwd(), "mockData", "GisSystemStatic.json");
|
||||
|
||||
export default function handler(req, res) {
|
||||
if (req.method === "GET") {
|
||||
try {
|
||||
const data = fs.readFileSync(filePath, "utf-8");
|
||||
res.status(200).json(JSON.parse(data));
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Fehler beim Lesen der GisSystemStatic.json" });
|
||||
}
|
||||
} else {
|
||||
res.status(405).json({ error: "Methode nicht erlaubt" });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user