Migra dal codice salvato in locale al codice condiviso

This commit is contained in:
Giuseppe Raffa
2026-01-06 17:36:58 +01:00
parent 8a88c31c75
commit ff1566d36b
30 changed files with 8985 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
const fs = require("fs");
const path = require("path");
module.exports = function(app, settings) {
// Serve mappa
app.get('/meb/map', (req, res) => {
const filePath = path.join(__dirname, "public", "map.html");
fs.readFile(filePath, "utf8", (err, html) => {
if (err) {
res.status(500).send("Errore nel caricamento della mappa");
return;
}
const token = settings?.mapboxKey ?? "";
const finalHtml = html.replace("{{MAPBOX_KEY}}", token);
res.setHeader("Content-Type", "text/html; charset=utf-8");
res.send(finalHtml);
});
});
// WebSocket forward: posizione in tempo reale
let lastPosition = null;
app.streambundle.getSelfStream("navigation.position").onValue(pos => {
lastPosition = pos;
});
// Endpoint JSON per marker barca (se vuoi usarlo invece del WS SignalK)
app.get('/meb/map/boat', (req, res) => {
if (!lastPosition) {
res.json({ error: "No position data available" });
return;
}
res.json(lastPosition);
});
}