From f2ef81fb7ba2029dfc054d6fdfc6ec62dd7b9eb9 Mon Sep 17 00:00:00 2001 From: posimai Date: Thu, 2 Apr 2026 19:28:19 +0900 Subject: [PATCH] fix: proxy VPS health via /api/vps-health to avoid browser cert errors --- posimai-dev/server.js | 15 +++++++++++++++ posimai-dev/station-b.html | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/posimai-dev/server.js b/posimai-dev/server.js index 744cbbe6..e17f7cf3 100644 --- a/posimai-dev/server.js +++ b/posimai-dev/server.js @@ -180,6 +180,21 @@ app.get('/api/gitea-commit', async (req, res) => { } catch (e) { res.json({ error: e.message }); } }); +// ── VPS health プロキシ (/api/vps-health) ────────────────────── +// ブラウザから直接叩くと自己署名証明書環境でCORSエラーになるためサーバー経由でプロキシ +app.get('/api/vps-health', async (req, res) => { + res.setHeader('Access-Control-Allow-Origin', '*'); + try { + const r = await fetch('https://api.soar-enrich.com/api/health', { + signal: AbortSignal.timeout(6000), + }); + const data = await r.json(); + res.json(data); + } catch (e) { + res.status(502).json({ error: e.message }); + } +}); + // ── サービス死活チェックプロキシ (/api/check?url=...) ────────── // ブラウザの mixed-content 制限を回避するためサーバー側から HTTP チェック app.get('/api/check', async (req, res) => { diff --git a/posimai-dev/station-b.html b/posimai-dev/station-b.html index 0a45c8c8..09fc14ff 100644 --- a/posimai-dev/station-b.html +++ b/posimai-dev/station-b.html @@ -707,7 +707,7 @@ setInterval(fetchGiteaCommit, 120000); // ── VPS メトリクス ───────────────────────────────────────────── async function fetchVpsHealth(){ try{ - const r=await fetch('https://api.soar-enrich.com/api/health',{signal:AbortSignal.timeout(6000)}); + const r=await fetch('/api/vps-health',{signal:AbortSignal.timeout(8000)}); const d=await r.json(); const memPct=d.mem_total_mb?Math.round(d.mem_used_mb/d.mem_total_mb*100):0; const diskPct=d.disk?.use_pct??0;