fix stuff + add stuff

This commit is contained in:
ashley 2025-09-28 17:10:57 +02:00
parent cdbce03236
commit be34d425b8

View File

@ -75,40 +75,45 @@ module.exports = function (app, config, renderTemplate) {
f.body.pipe(res); f.body.pipe(res);
}); });
app.get("/api/nominatim/search", async (req, res) => { app.get("/api/nominatim/search", async (req, res) => {
const qs = new URLSearchParams(req.query).toString();
const url = `https://nominatim.openstreetmap.org/search?${qs}`;
try { try {
const r = await fetch(url, { const url = new URL("https://nominatim.openstreetmap.org/search");
headers: { // Forward all query params (format, q, limit, etc.)
"Accept-Language": req.headers["accept-language"] || "en", for (const [key, value] of Object.entries(req.query)) {
"User-Agent": "PokeWeather Proxy (pokeweather.local)" url.searchParams.set(key, value);
} }
// Force JSON output if not specified
if (!url.searchParams.has("format")) url.searchParams.set("format", "json");
const r = await fetch(url.toString(), {
headers: { "Accept-Language": req.headers["accept-language"] || "en" }
}); });
res.status(r.status); const data = await r.json();
r.body.pipe(res); res.json(data);
} catch (err) { } catch (err) {
res.status(500).json({ error: "Failed to reach Nominatim search" }); res.status(500).json({ error: "Failed to fetch from nominatim" });
} }
}); });
// Proxy for reverse geocoding
app.get("/api/nominatim/reverse", async (req, res) => { app.get("/api/nominatim/reverse", async (req, res) => {
const qs = new URLSearchParams(req.query).toString();
const url = `https://nominatim.openstreetmap.org/reverse?${qs}`;
try { try {
const r = await fetch(url, { const url = new URL("https://nominatim.openstreetmap.org/reverse");
headers: { for (const [key, value] of Object.entries(req.query)) {
"Accept-Language": req.headers["accept-language"] || "en", url.searchParams.set(key, value);
"User-Agent": "PokeWeather Proxy (pokeweather.local)" }
} if (!url.searchParams.has("format")) url.searchParams.set("format", "json");
const r = await fetch(url.toString(), {
headers: { "Accept-Language": req.headers["accept-language"] || "en" }
}); });
res.status(r.status); const data = await r.json();
r.body.pipe(res); res.json(data);
} catch (err) { } catch (err) {
res.status(500).json({ error: "Failed to reach Nominatim reverse" }); res.status(500).json({ error: "Failed to fetch from nominatim" });
} }
}); });
app.get("/avatars/ytc/:v", async function (req, res) { app.get("/avatars/ytc/:v", async function (req, res) {
var url = `https://yt3.googleusercontent.com/ytc/${req.params.v.replace("ytc", "")}`; var url = `https://yt3.googleusercontent.com/ytc/${req.params.v.replace("ytc", "")}`;