Files
nodeMap/pages/api/gis-proxy.js

60 lines
2.0 KiB
JavaScript

// /pages/api/gis-proxy.js
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 baseUrl = process.env.NEXT_PUBLIC_GIS_SERVER_URL;
const targetUrl = `${baseUrl}/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 });
}
}