Files
nodeMap/pages/api/gis-proxy.js
ISA 20a2abd9b6 feat: API-Proxy für SOAP-Webservice implementiert
- API-Route hinzugefügt: /api/gisStationsStaticDistrict
- Dynamisches Lesen von URL-Parametern (idMap, idUser) aus Anfrage
- SOAP-Anfrage an ASP.NET-Webservice weitergeleitet
- XML-Antwort verarbeitet und zurückgegeben
- CORS-Header und OPTIONS-Preflight für Sicherheit konfiguriert
- Fehlerbehandlung und Debug-Logs integriert
2025-01-02 13:59:18 +01:00

58 lines
1.9 KiB
JavaScript

export default async function handler(req, res) {
// CORS-Header setzen
res.setHeader("Access-Control-Allow-Credentials", true);
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "POST,OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, SOAPAction");
// OPTIONS-Preflight-Anfrage sofort beenden
if (req.method === "OPTIONS") {
res.status(200).end();
return;
}
// Ziel-URL direkt auf die Methode
const targetUrl = "http://10.10.0.70/talas5/ClientData/WebServiceMap.asmx";
// SOAP-Envelope für die Methode "GisStationsStaticDistrict"
const soapEnvelope = `
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GisStationsStaticDistrict xmlns="http://tempuri.org/">
<idMap>12</idMap>
<idUser>484</idUser>
</GisStationsStaticDistrict>
</soap:Body>
</soap:Envelope>
`;
try {
// Anfrage an SOAP-Server senden
const response = await fetch(targetUrl, {
method: "POST",
headers: {
"Content-Type": "text/xml; charset=utf-8",
SOAPAction: '"http://tempuri.org/GisStationsStaticDistrict"', // SOAPAction mit Anführungszeichen
},
body: soapEnvelope,
});
// Debugging: Status und Text ausgeben
const text = await response.text();
console.log("SOAP-Antwort:", text);
if (!response.ok) {
throw new Error(`Server antwortet mit Status ${response.status}`);
}
// Erfolgreiche Antwort senden
res.status(200).send(text);
} catch (error) {
console.error("Fehler beim SOAP-Aufruf:", error);
res.status(500).json({ error: "Fehler beim SOAP-Aufruf", details: error.message });
}
}