feat: basePath-Konfiguration von .env in config.json verschoben
basePath wird jetzt in config.json gepflegt statt als NEXT_PUBLIC_BASE_PATH in .env.* Alle relevanten Code-Stellen lesen basePath dynamisch aus config.json Dokumentation und Beispiele in Markdown-Dateien entsprechend angepasst Erhöhte Flexibilität für Deployments ohne Rebuild
This commit is contained in:
@@ -20,9 +20,8 @@ NEXT_PUBLIC_USE_MOCKS=true
|
||||
# Ein Unterordner in der dort hinter liegenden Ordnerstruktur (z.B. http://talasserver/talas5/nodemap/api/talas_v5_DB/ usw.)
|
||||
# kann bleiben da der Kunde diesen Unterordner talas:v5_db nicht ändert.
|
||||
#Füge in deiner .env.local Datei die folgende Zeile hinzu wenn du einen Unterordner verwenden möchtest mit entsprechende Bezeichnung.
|
||||
# z.B. http://10.10.0.13/talas5/index.aspx -> NEXT_PUBLIC_BASE_PATH=/talas5
|
||||
# z.B. http://10.10.0.13/xyz/index.aspx -> NEXT_PUBLIC_BASE_PATH=/xyz
|
||||
NEXT_PUBLIC_BASE_PATH=/talas5
|
||||
# Oder leer lassen für direkten Zugriff -> NEXT_PUBLIC_BASE_PATH=
|
||||
# z.B. http://10.10.0.13/talas5/index.aspx -> basePath in config.json auf /talas5 setzen
|
||||
# z.B. http://10.10.0.13/xyz/index.aspx -> basePath in config.json auf /xyz setzen
|
||||
# basePath wird jetzt in public/config.json gepflegt
|
||||
# App-Versionsnummer
|
||||
NEXT_PUBLIC_APP_VERSION=1.1.317
|
||||
NEXT_PUBLIC_APP_VERSION=1.1.318
|
||||
|
||||
@@ -20,10 +20,9 @@ NEXT_PUBLIC_USE_MOCKS=false
|
||||
# Ein Unterordner in der dort hinter liegenden Ordnerstruktur (z.B. http://talasserver/talas5/nodemap/api/talas_v5_DB/ usw.)
|
||||
# kann bleiben da der Kunde diesen Unterordner talas:v5_db nicht ändert.
|
||||
#Füge in deiner .env.local Datei die folgende Zeile hinzu wenn du einen Unterordner verwenden möchtest mit entsprechende Bezeichnung.
|
||||
# z.B. http://10.10.0.13/talas5/index.aspx -> NEXT_PUBLIC_BASE_PATH=/talas5
|
||||
# z.B. http://10.10.0.13/xyz/index.aspx -> NEXT_PUBLIC_BASE_PATH=/xyz
|
||||
NEXT_PUBLIC_BASE_PATH=/talas5
|
||||
# Oder leer lassen für direkten Zugriff -> NEXT_PUBLIC_BASE_PATH=
|
||||
# z.B. http://10.10.0.13/talas5/index.aspx -> basePath in config.json auf /talas5 setzen
|
||||
# z.B. http://10.10.0.13/xyz/index.aspx -> basePath in config.json auf /xyz setzen
|
||||
# basePath wird jetzt in public/config.json gepflegt
|
||||
|
||||
# App-Versionsnummer
|
||||
NEXT_PUBLIC_APP_VERSION=1.1.317
|
||||
NEXT_PUBLIC_APP_VERSION=1.1.318
|
||||
|
||||
@@ -250,7 +250,7 @@ das Objekt selbst
|
||||
### ♻️ Refactor
|
||||
|
||||
- Alle hartkodierten `/talas5/`-Pfadangaben entfernt
|
||||
- Dynamischer `basePath` eingeführt über `.env.local → NEXT_PUBLIC_BASE_PATH`
|
||||
- Dynamischer `basePath` eingeführt über `public/config.json → basePath`
|
||||
- Unterstützt jetzt auch den Betrieb ohne Unterverzeichnis
|
||||
|
||||
### 🧠 Architektur
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
// config/paths.js
|
||||
const basePathRaw = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
const BASE_PATH = basePathRaw.replace(/^\/|\/$/g, "");
|
||||
export const BASE_URL = BASE_PATH ? `/${BASE_PATH}` : "";
|
||||
let __configCache;
|
||||
export async function getBaseUrl() {
|
||||
if (__configCache) return __configCache;
|
||||
const res = await fetch("/config.json");
|
||||
if (!res.ok) throw new Error("config.json konnte nicht geladen werden");
|
||||
const config = await res.json();
|
||||
const basePath = (config.basePath || "").replace(/^\/|\/$/g, "");
|
||||
__configCache = basePath ? `/${basePath}` : "";
|
||||
return __configCache;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ sequenceDiagram
|
||||
|
||||
- **Konfigurierbarer basePath:**
|
||||
- **Konfigurierbarer basePath:**
|
||||
Pfad wie `/talas5` ist optional und kann per Umgebungsvariable `NEXT_PUBLIC_BASE_PATH` gesetzt
|
||||
Pfad wie `/talas5` ist optional und wird jetzt in `public/config.json` als `basePath` gepflegt
|
||||
werden.
|
||||
Die Konfiguration erfolgt je nach Umgebung über:
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
# 📁 paths.js
|
||||
|
||||
Berechnet den sauberen `BASE_URL`-Pfad basierend auf `.env.production` oder
|
||||
`.env.development → NEXT_PUBLIC_BASE_PATH`.
|
||||
`public/config.json → basePath`.
|
||||
Entfernt führende und abschließende Slashes.
|
||||
|
||||
## Beispiel
|
||||
|
||||
Wenn `NEXT_PUBLIC_BASE_PATH = "/talas5/"`, wird `BASE_URL = "/talas5"` gesetzt.
|
||||
Wenn `basePath = "/talas5/"` in config.json gesetzt ist, wird `BASE_URL = "/talas5"` verwendet.
|
||||
|
||||
```js
|
||||
const BASE_PATH = basePathRaw.replace(/^\/|\/$/g, "");
|
||||
|
||||
@@ -12,17 +12,17 @@ NodeMap verwendet Umgebungsvariablen zur Steuerung von API-Verhalten, Serverpfad
|
||||
|
||||
## 🔧 Wichtige Variablen
|
||||
|
||||
| Variable | Beispielwert | Beschreibung |
|
||||
| --------------------------- | ------------------- | --------------------------------------------------------------------- |
|
||||
| `DB_HOST` | `localhost` | Adresse des Datenbankservers (MySQL) |
|
||||
| `DB_PORT` | `3306` | Port für die Datenbankverbindung |
|
||||
| `DB_NAME` | `talas` | Datenbankname |
|
||||
| `DB_USER` | `root` | Benutzername für MySQL |
|
||||
| `DB_PASSWORD` | `geheim` | Passwort für MySQL |
|
||||
| `NEXT_PUBLIC_API_PORT_MODE` | `prod` oder `dev` | Steuert API-Routing bei Services (z. B. Portwechsel für lokal) |
|
||||
| `NEXT_PUBLIC_USE_MOCKS` | `true` oder `false` | Aktiviert den Mockdaten-Modus über `/api/mocks/...` |
|
||||
| `NEXT_PUBLIC_BASE_PATH` | `/talas5` oder leer | Optionaler Pfad, falls App unter Subpfad läuft (z. B. IIS) |
|
||||
| `NEXT_PUBLIC_DEBUG` | `true` oder `false` | Aktiviert zusätzliche `console.log` Ausgaben für Debugging im Browser |
|
||||
| Variable | Beispielwert | Beschreibung |
|
||||
| --------------------------- | ------------------- | -------------------------------------------------------------------------------------------------------- |
|
||||
| `DB_HOST` | `localhost` | Adresse des Datenbankservers (MySQL) |
|
||||
| `DB_PORT` | `3306` | Port für die Datenbankverbindung |
|
||||
| `DB_NAME` | `talas` | Datenbankname |
|
||||
| `DB_USER` | `root` | Benutzername für MySQL |
|
||||
| `DB_PASSWORD` | `geheim` | Passwort für MySQL |
|
||||
| `NEXT_PUBLIC_API_PORT_MODE` | `prod` oder `dev` | Steuert API-Routing bei Services (z. B. Portwechsel für lokal) |
|
||||
| `NEXT_PUBLIC_USE_MOCKS` | `true` oder `false` | Aktiviert den Mockdaten-Modus über `/api/mocks/...` |
|
||||
| `basePath` (in config.json) | `/talas5` oder leer | Optionaler Pfad, falls App unter Subpfad läuft (z. B. IIS). Wird jetzt in `public/config.json` gepflegt. |
|
||||
| `NEXT_PUBLIC_DEBUG` | `true` oder `false` | Aktiviert zusätzliche `console.log` Ausgaben für Debugging im Browser |
|
||||
|
||||
## 📦 Beispiel `.env.production`
|
||||
|
||||
@@ -34,7 +34,11 @@ DB_USER=root
|
||||
DB_PASSWORD=geheim
|
||||
NEXT_PUBLIC_API_PORT_MODE=prod
|
||||
NEXT_PUBLIC_USE_MOCKS=false
|
||||
NEXT_PUBLIC_BASE_PATH=/talas5
|
||||
// public/config.json
|
||||
{
|
||||
...
|
||||
"basePath": "/talas5"
|
||||
}
|
||||
NEXT_PUBLIC_DEBUG=false
|
||||
```
|
||||
|
||||
@@ -48,7 +52,11 @@ DB_USER=root
|
||||
DB_PASSWORD=geheim
|
||||
NEXT_PUBLIC_API_PORT_MODE=dev
|
||||
NEXT_PUBLIC_USE_MOCKS=true
|
||||
NEXT_PUBLIC_BASE_PATH=/talas5
|
||||
// public/config.json
|
||||
{
|
||||
...
|
||||
"basePath": "/talas5"
|
||||
}
|
||||
NEXT_PUBLIC_DEBUG=true
|
||||
```
|
||||
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "nodemap",
|
||||
"version": "1.1.317",
|
||||
"version": "1.1.318",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "nodemap",
|
||||
"version": "1.1.317",
|
||||
"version": "1.1.318",
|
||||
"dependencies": {
|
||||
"@emotion/react": "^11.13.3",
|
||||
"@emotion/styled": "^11.13.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nodemap",
|
||||
"version": "1.1.317",
|
||||
"version": "1.1.318",
|
||||
"dependencies": {
|
||||
"@emotion/react": "^11.13.3",
|
||||
"@emotion/styled": "^11.13.0",
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
"local": "http://localhost/talas5/TileMap/mapTiles/{z}/{x}/{y}.png",
|
||||
"osm": "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||
},
|
||||
"active": "osm"
|
||||
"active": "osm",
|
||||
"basePath": "/talas5"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
// /services/webservice/fetchGisLinesStatusService.js
|
||||
let __configCache;
|
||||
async function getConfig() {
|
||||
if (__configCache) return __configCache;
|
||||
const res = await fetch("/config.json");
|
||||
if (!res.ok) throw new Error("config.json konnte nicht geladen werden");
|
||||
__configCache = await res.json();
|
||||
return __configCache;
|
||||
}
|
||||
|
||||
export const fetchGisLinesStatusService = async () => {
|
||||
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
const config = await getConfig();
|
||||
const basePath = config.basePath || "";
|
||||
|
||||
if (useMocks) {
|
||||
const mockBasePath = "/api/mocks/webservice/gisLinesStatus";
|
||||
@@ -16,11 +26,9 @@ export const fetchGisLinesStatusService = async () => {
|
||||
}
|
||||
|
||||
const mockData = await response.json();
|
||||
|
||||
if (!Array.isArray(mockData.Statis)) {
|
||||
throw new Error("Ungültige Struktur: 'Status' fehlt im Mock");
|
||||
}
|
||||
|
||||
return mockData.Statis;
|
||||
} else {
|
||||
const baseUrl = `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx`;
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
let __configCache;
|
||||
async function getConfig() {
|
||||
if (__configCache) return __configCache;
|
||||
const res = await fetch("/config.json");
|
||||
if (!res.ok) throw new Error("config.json konnte nicht geladen werden");
|
||||
__configCache = await res.json();
|
||||
return __configCache;
|
||||
}
|
||||
|
||||
export const fetchGisStationsMeasurementsService = async () => {
|
||||
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
const config = await getConfig();
|
||||
const basePath = config.basePath || "";
|
||||
|
||||
if (useMocks) {
|
||||
const mockBasePath = "/api/mocks/webservice/gisStationsMeasurements";
|
||||
|
||||
@@ -5,9 +5,19 @@
|
||||
* @returns {Promise<Array>} Liste mit Points[]
|
||||
* @throws {Error} bei Fehler oder ungültiger Antwortstruktur
|
||||
*/
|
||||
let __configCache;
|
||||
async function getConfig() {
|
||||
if (__configCache) return __configCache;
|
||||
const res = await fetch("/config.json");
|
||||
if (!res.ok) throw new Error("config.json konnte nicht geladen werden");
|
||||
__configCache = await res.json();
|
||||
return __configCache;
|
||||
}
|
||||
|
||||
export const fetchGisStationsStaticDistrictService = async () => {
|
||||
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
const config = await getConfig();
|
||||
const basePath = config.basePath || "";
|
||||
|
||||
if (useMocks) {
|
||||
const mockBasePath = "/api/mocks/webservice/gisStationsStaticDistrict";
|
||||
|
||||
@@ -5,9 +5,19 @@
|
||||
* @returns {Promise<Array>} Liste mit Statis[]
|
||||
* @throws {Error} bei Fehler oder ungültiger Antwortstruktur
|
||||
*/
|
||||
let __configCache;
|
||||
async function getConfig() {
|
||||
if (__configCache) return __configCache;
|
||||
const res = await fetch("/config.json");
|
||||
if (!res.ok) throw new Error("config.json konnte nicht geladen werden");
|
||||
__configCache = await res.json();
|
||||
return __configCache;
|
||||
}
|
||||
|
||||
export const fetchGisStationsStatusDistrictService = async () => {
|
||||
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
const config = await getConfig();
|
||||
const basePath = config.basePath || "";
|
||||
|
||||
if (useMocks) {
|
||||
const mockBasePath = "/api/mocks/webservice/gisStationsStatusDistrict";
|
||||
|
||||
@@ -4,9 +4,19 @@
|
||||
* @returns {Promise<Array>} Liste mit Systems[]
|
||||
* @throws {Error} bei Fehler oder ungültiger Antwortstruktur
|
||||
*/
|
||||
let __configCache;
|
||||
async function getConfig() {
|
||||
if (__configCache) return __configCache;
|
||||
const res = await fetch("/config.json");
|
||||
if (!res.ok) throw new Error("config.json konnte nicht geladen werden");
|
||||
__configCache = await res.json();
|
||||
return __configCache;
|
||||
}
|
||||
|
||||
export const fetchGisSystemStaticService = async () => {
|
||||
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
const config = await getConfig();
|
||||
const basePath = config.basePath || "";
|
||||
|
||||
if (useMocks) {
|
||||
const mockBasePath = "/api/mocks/webservice/gisSystemStatic";
|
||||
|
||||
@@ -4,9 +4,19 @@
|
||||
* @returns {Promise<Array>} Rechte-Array
|
||||
* @throws {Error} bei Lade- oder Strukturfehler
|
||||
*/
|
||||
let __configCache;
|
||||
async function getConfig() {
|
||||
if (__configCache) return __configCache;
|
||||
const res = await fetch("/config.json");
|
||||
if (!res.ok) throw new Error("config.json konnte nicht geladen werden");
|
||||
__configCache = await res.json();
|
||||
return __configCache;
|
||||
}
|
||||
|
||||
export const fetchUserRightsService = async () => {
|
||||
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
const config = await getConfig();
|
||||
const basePath = config.basePath || "";
|
||||
|
||||
if (useMocks) {
|
||||
const mockBasePath = "/api/mocks/webservice/gisSystemStatic";
|
||||
|
||||
@@ -35,7 +35,14 @@ export const createAndSetDevices = async (
|
||||
setMarkersFunction([]);
|
||||
return;
|
||||
}
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
let basePath = "";
|
||||
try {
|
||||
const res = await fetch("/config.json");
|
||||
if (res.ok) {
|
||||
const config = await res.json();
|
||||
basePath = config.basePath || "";
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
try {
|
||||
const state = store.getState();
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
// utils/openInNewTab.js
|
||||
|
||||
export function openInNewTab(e, target) {
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
export async function openInNewTab(e, target) {
|
||||
const res = await fetch("/config.json");
|
||||
const config = await res.json();
|
||||
const basePath = config.basePath || "";
|
||||
const url = new URL(window.location.origin);
|
||||
const originWithoutPort = `${url.protocol}//${url.hostname}`; // ohne Port!
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import { updatePolylineCoordinatesThunk } from "../../redux/thunks/database/poly
|
||||
import { openInNewTab } from "../../utils/openInNewTab";
|
||||
|
||||
//--------------------------------------------
|
||||
export const setupPolylines = (
|
||||
export const setupPolylines = async (
|
||||
map,
|
||||
linePositions,
|
||||
lineColors,
|
||||
@@ -29,7 +29,14 @@ export const setupPolylines = (
|
||||
polylineVisible
|
||||
) => {
|
||||
const mode = process.env.NEXT_PUBLIC_API_PORT_MODE;
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
let basePath = "";
|
||||
try {
|
||||
const res = await fetch("/config.json");
|
||||
if (res.ok) {
|
||||
const config = await res.json();
|
||||
basePath = config.basePath || "";
|
||||
}
|
||||
} catch (e) {}
|
||||
if (!polylineVisible) {
|
||||
//console.warn("Polylines deaktiviert - keine Zeichnung");
|
||||
return { markers: [], polylines: [] };
|
||||
|
||||
Reference in New Issue
Block a user