Files
nodeMap/docs/server/pages/api/apiProxy.md
Ismail Ali b097a76d34 docs+refactor: Proxy [...path].js auf dynamische Ziel-URL umgestellt (v1.1.77)
- entfernt: NEXT_PUBLIC_SERVER_URL aus .env.local
- verwendet jetzt API_PORT_MODE zur Zielermittlung (dev = :80)
- neue technische Dokumentation unter /docs/server/pages/api/apiProxy.md
- CHANGELOG.md und appVersion.js aktualisiert (1.1.77)
2025-05-17 01:10:18 +02:00

77 lines
1.6 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 🌐 API Proxy [...path].js
## Zweck
Diese Datei (`pages/api/[...path].js`) dient als **Catch-All Proxy**
für externe Webservice-Aufrufe über die Next.js API-Routing-Struktur.
Sie leitet alle Anfragen unter `/api/...` an einen Zielserver weiter.
---
## Technologie
Verwendet wird:
- [`http-proxy-middleware`](https://github.com/chimurai/http-proxy-middleware)
- Dynamische Zielauswahl basierend auf Umgebungsvariable `NEXT_PUBLIC_API_PORT_MODE`
---
## Ziel-URL-Konfiguration
```js
const mode = process.env.NEXT_PUBLIC_API_PORT_MODE;
const target =
mode === "dev"
? "http://localhost:80"
: "http://localhost"; // oder z.B. http://10.10.0.13
```
➡ Dadurch entfällt die feste Konfiguration über `NEXT_PUBLIC_SERVER_URL`.
---
## Beispiel: Weiterleitung
Request im Browser:
```
GET /api/talas5/ClientData/WebServiceMap.asmx/GisSystemStatic?idMap=12&idUser=484
```
→ wird weitergeleitet an:
```
http://localhost/talas5/ClientData/WebServiceMap.asmx/GisSystemStatic?idMap=12&idUser=484
```
---
## Verwendete Einstellungen
```js
export default createProxyMiddleware({
target,
changeOrigin: true,
pathRewrite: {
"^/api": "/", // entfernt /api aus dem Pfad
},
logLevel: "debug",
});
```
---
## Vorteile
| Punkt | Nutzen |
|---------------------------|------------------------------------------|
| Keine doppelte API-Konfiguration | ✅ `.env.local` bereinigt |
| Wiederverwendbar & flexibel | ✅ funktioniert lokal & auf Servern |
| Klar gekapselt in `[...path].js` | ✅ übersichtlich |
---
📄 Pfad: `/docs/server/pages/api/apiProxy.md`