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)
This commit is contained in:
Ismail Ali
2025-05-17 01:10:18 +02:00
parent 30bbb61f1c
commit b097a76d34
6 changed files with 102 additions and 9 deletions

View File

@@ -0,0 +1,77 @@
# 🌐 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`