feat: osm von server als proxy für den client

This commit is contained in:
ISA
2025-09-09 16:11:23 +02:00
parent 4befddd440
commit 61ed542ea4
7 changed files with 39 additions and 8 deletions

View File

@@ -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