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) <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,10 @@ export const dynamic = "force-dynamic";
|
|||||||
const TILE_CACHE_INTERNAL = "http://tile-cache:80";
|
const TILE_CACHE_INTERNAL = "http://tile-cache:80";
|
||||||
const MARTIN_INTERNAL = "http://martin:3000";
|
const MARTIN_INTERNAL = "http://martin:3000";
|
||||||
const PMTILES_URL = process.env.NEXT_PUBLIC_PMTILES_URL || "";
|
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 || "";
|
const N8N_WEBHOOK_URL = process.env.N8N_WEBHOOK_URL || "";
|
||||||
|
|
||||||
type NginxStatus = {
|
type NginxStatus = {
|
||||||
@@ -88,7 +92,7 @@ export async function GET() {
|
|||||||
// 3. PMTiles info
|
// 3. PMTiles info
|
||||||
if (PMTILES_URL) {
|
if (PMTILES_URL) {
|
||||||
try {
|
try {
|
||||||
const res = await fetchWithTimeout(PMTILES_URL, 3000);
|
const res = await fetchWithTimeout(PMTILES_FETCH_URL, 3000);
|
||||||
result.pmtiles = {
|
result.pmtiles = {
|
||||||
url: PMTILES_URL,
|
url: PMTILES_URL,
|
||||||
status: res.ok ? "ok" : `HTTP ${res.status}`,
|
status: res.ok ? "ok" : `HTTP ${res.status}`,
|
||||||
@@ -138,7 +142,7 @@ export async function GET() {
|
|||||||
async function getPmtilesInfo(): Promise<{ size: string; lastModified: string } | null> {
|
async function getPmtilesInfo(): Promise<{ size: string; lastModified: string } | null> {
|
||||||
if (!PMTILES_URL) return null;
|
if (!PMTILES_URL) return null;
|
||||||
try {
|
try {
|
||||||
const res = await fetchWithTimeout(PMTILES_URL, 3000);
|
const res = await fetchWithTimeout(PMTILES_FETCH_URL, 3000);
|
||||||
return {
|
return {
|
||||||
size: res.headers.get("content-length")
|
size: res.headers.get("content-length")
|
||||||
? `${(parseInt(res.headers.get("content-length") ?? "0", 10) / 1024 / 1024).toFixed(1)} MB`
|
? `${(parseInt(res.headers.get("content-length") ?? "0", 10) / 1024 / 1024).toFixed(1)} MB`
|
||||||
|
|||||||
Reference in New Issue
Block a user