From adc0b0a0d0577e4a6763a1f412528f7b110fb4ed Mon Sep 17 00:00:00 2001 From: AI Assistant Date: Sun, 29 Mar 2026 16:01:47 +0300 Subject: [PATCH] fix(monitor): resolve relative PMTILES_URL for server-side health check Server-side fetch() cannot resolve relative URLs like /tiles/pmtiles/... Route through internal tile-cache proxy (http://tile-cache:80) instead. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/app/api/geoportal/monitor/route.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/app/api/geoportal/monitor/route.ts b/src/app/api/geoportal/monitor/route.ts index 9d40dec..392259f 100644 --- a/src/app/api/geoportal/monitor/route.ts +++ b/src/app/api/geoportal/monitor/route.ts @@ -10,6 +10,10 @@ export const dynamic = "force-dynamic"; const TILE_CACHE_INTERNAL = "http://tile-cache:80"; const MARTIN_INTERNAL = "http://martin:3000"; const PMTILES_URL = process.env.NEXT_PUBLIC_PMTILES_URL || ""; +// Server-side fetch needs absolute URL — resolve relative paths through tile-cache +const PMTILES_FETCH_URL = PMTILES_URL.startsWith("/") + ? `${TILE_CACHE_INTERNAL}${PMTILES_URL.replace(/^\/tiles/, "")}` + : PMTILES_URL; const N8N_WEBHOOK_URL = process.env.N8N_WEBHOOK_URL || ""; type NginxStatus = { @@ -88,7 +92,7 @@ export async function GET() { // 3. PMTiles info if (PMTILES_URL) { try { - const res = await fetchWithTimeout(PMTILES_URL, 3000); + const res = await fetchWithTimeout(PMTILES_FETCH_URL, 3000); result.pmtiles = { url: PMTILES_URL, status: res.ok ? "ok" : `HTTP ${res.status}`, @@ -138,7 +142,7 @@ export async function GET() { async function getPmtilesInfo(): Promise<{ size: string; lastModified: string } | null> { if (!PMTILES_URL) return null; try { - const res = await fetchWithTimeout(PMTILES_URL, 3000); + const res = await fetchWithTimeout(PMTILES_FETCH_URL, 3000); return { size: res.headers.get("content-length") ? `${(parseInt(res.headers.get("content-length") ?? "0", 10) / 1024 / 1024).toFixed(1)} MB`