From 61ed542ea45cf9d16fef333e35a30303e51c1af6 Mon Sep 17 00:00:00 2001 From: ISA Date: Tue, 9 Sep 2025 16:11:23 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20osm=20von=20server=20als=20proxy=20f?= =?UTF-8?q?=C3=BCr=20den=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 2 +- .env.production | 2 +- package-lock.json | 4 ++-- package.json | 2 +- public/config.json | 4 ++-- server.js | 27 ++++++++++++++++++++++++++- utils/initializeMap.js | 6 ++++++ 7 files changed, 39 insertions(+), 8 deletions(-) diff --git a/.env.development b/.env.development index 58abdc7ad..d5731f657 100644 --- a/.env.development +++ b/.env.development @@ -23,4 +23,4 @@ NEXT_PUBLIC_USE_MOCKS=true # 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.348 +NEXT_PUBLIC_APP_VERSION=1.1.349 diff --git a/.env.production b/.env.production index 90ca0d07c..14f68ac2b 100644 --- a/.env.production +++ b/.env.production @@ -24,4 +24,4 @@ NEXT_PUBLIC_USE_MOCKS=false # basePath wird jetzt in public/config.json gepflegt # App-Versionsnummer -NEXT_PUBLIC_APP_VERSION=1.1.348 +NEXT_PUBLIC_APP_VERSION=1.1.349 diff --git a/package-lock.json b/package-lock.json index 1d055d1c9..e4f1f9891 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "nodemap", - "version": "1.1.348", + "version": "1.1.349", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "nodemap", - "version": "1.1.348", + "version": "1.1.349", "dependencies": { "@emotion/react": "^11.13.3", "@emotion/styled": "^11.13.0", diff --git a/package.json b/package.json index 2a3a90801..862891db6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodemap", - "version": "1.1.348", + "version": "1.1.349", "dependencies": { "@emotion/react": "^11.13.3", "@emotion/styled": "^11.13.0", diff --git a/public/config.json b/public/config.json index 66664da51..8255727d9 100644 --- a/public/config.json +++ b/public/config.json @@ -13,8 +13,8 @@ "maxZoom": 15 }, "osm": { - "url": "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", - "_comment": "OpenStreetMap Online-Kartenquelle", + "url": "/tiles/{z}/{x}/{y}.png", + "_comment": "OpenStreetMap Online-Kartenquelle über Server-Proxy (relativ)", "minZoom": 0, "maxZoom": 19 } diff --git a/server.js b/server.js index 740073e99..f449f76b5 100644 --- a/server.js +++ b/server.js @@ -27,10 +27,35 @@ const extractData = (json, name) => { }; app.prepare().then(() => { - const server = createServer((req, res) => { + const express = require("express"); + const expressApp = express(); + // Proxy-Route für Karten-Tiles + expressApp.get("/tiles/:z/:x/:y.png", async (req, res) => { + const { z, x, y } = req.params; + // OSM-Subdomain (a, b, c) zufällig wählen + const subdomains = ["a", "b", "c"]; + const s = subdomains[Math.floor(Math.random() * subdomains.length)]; + const tileUrl = `https://${s}.tile.openstreetmap.org/${z}/${x}/${y}.png`; + try { + const response = await fetch(tileUrl); + if (!response.ok) { + res.status(response.status).send("Tile not found"); + return; + } + res.set("Content-Type", "image/png"); + response.body.pipe(res); + } catch (err) { + res.status(500).send("Error fetching tile"); + } + }); + + // Alle anderen Routen an Next.js + expressApp.all("*", (req, res) => { handle(req, res); }); + const server = createServer(expressApp); + const io = new Server(server); // ✅ Globaler Cache für alle aktuellen Daten diff --git a/utils/initializeMap.js b/utils/initializeMap.js index 276d027ff..801eca027 100644 --- a/utils/initializeMap.js +++ b/utils/initializeMap.js @@ -89,6 +89,12 @@ export const initializeMap = ( if (config.tileSources && config.active && config.tileSources[config.active]) { const tileSource = config.tileSources[config.active]; tileLayerUrl = tileSource.url || tileLayerUrl; + // Dynamische URL für Server-Tiles + if (tileLayerUrl.startsWith("/tiles") || tileLayerUrl.startsWith("tiles")) { + tileLayerUrl = `${window.location.origin.replace(/\/$/, "")}${ + tileLayerUrl.startsWith("/") ? tileLayerUrl : "/" + tileLayerUrl + }`; + } minZoom = tileSource.minZoom ?? minZoom; maxZoom = tileSource.maxZoom ?? maxZoom; }