docs
This commit is contained in:
45
docs/pages/api/[...path].md
Normal file
45
docs/pages/api/[...path].md
Normal file
@@ -0,0 +1,45 @@
|
||||
<!-- /docs/pages/api/[...path].md -->
|
||||
|
||||
# 🌐 [...path].js
|
||||
|
||||
Next.js API-Proxy-Handler mit `http-proxy-middleware`.
|
||||
Dient als Middleware zur Weiterleitung von API-Requests an das Backend (z. B. Raspberry Pi oder Entwicklungsserver).
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Funktion
|
||||
|
||||
- Leitet alle Requests von `/api/...` an das definierte `target` weiter
|
||||
- Entfernt `/api` aus dem URL-Pfad
|
||||
- Erlaubt Cross-Origin Requests mit `changeOrigin: true`
|
||||
|
||||
---
|
||||
|
||||
## Ziel-Logik
|
||||
|
||||
```js
|
||||
const mode = process.env.NEXT_PUBLIC_API_PORT_MODE;
|
||||
const target = mode === "dev" ? "http://localhost:80" : "http://localhost";
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Beispiel
|
||||
|
||||
- Frontend-Request: `GET /api/GisStationsStaticDistrict`
|
||||
- Weitergeleitet an: `GET http://localhost:80/GisStationsStaticDistrict`
|
||||
|
||||
---
|
||||
|
||||
## Besonderheiten
|
||||
|
||||
- Ermöglicht portunabhängige Proxy-Nutzung über `.env`
|
||||
- Setzt `logLevel: "debug"` zur Diagnose
|
||||
|
||||
---
|
||||
|
||||
## Pfad
|
||||
|
||||
```bash
|
||||
/pages/api/[...path].js
|
||||
```
|
||||
Reference in New Issue
Block a user