fix: Admin Panel health checks work via reverse proxy

- loadServiceUrls: use window.location.origin for remote access, localhost for local dev
- testCoreApi: use /api/v1/health for remote, /health for localhost
- testProxy: health check path works for both
- testMbe: already uses getApiBase() which handles both cases

This fixes the issue where Admin Panel showed offline when accessed via
https://nextorage.momentry.ddns.net because localhost health checks
point to user's machine, not the server.
This commit is contained in:
2026-10-23 21:35:29 +08:00
parent 88867e80e5
commit fa7a9e1084

View File

@@ -799,12 +799,17 @@ function serviceState(name: string) {
function loadServiceUrls() {
const stored = localStorage.getItem('service_urls')
// Always use localhost for services - they run on the same machine
const defaultCore = 'http://localhost:3002'
const defaultMarkbase = 'http://localhost:11438'
const defaultMbe = 'http://localhost:8080'
const defaultProxy = 'http://localhost:8888'
const defaultWorker = 'http://localhost:11438'
// Use current origin for services - works both locally and via reverse proxy
const currentOrigin = window.location.origin
const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
// Local dev: use direct localhost ports
// Remote access: use current origin (reverse proxy forwards requests)
const defaultCore = isLocalhost ? 'http://localhost:3002' : currentOrigin
const defaultMarkbase = isLocalhost ? 'http://localhost:11438' : currentOrigin
const defaultMbe = isLocalhost ? 'http://localhost:8080' : currentOrigin
const defaultProxy = isLocalhost ? 'http://localhost:8888' : currentOrigin
const defaultWorker = isLocalhost ? 'http://localhost:11438' : currentOrigin
if (stored) {
try {
@@ -856,8 +861,10 @@ async function testCoreApi() {
testingCore.value = true
coreInfo.value = null
try {
// Core API directly serves /health on localhost
const healthUrl = `${coreApiUrl.value}/health`
const isLocalhost = coreApiUrl.value.includes('localhost') || coreApiUrl.value.includes('127.0.0.1')
// Localhost: direct /health path
// Remote: via reverse proxy at /api/v1/health
const healthUrl = isLocalhost ? `${coreApiUrl.value}/health` : `${coreApiUrl.value}/api/v1/health`
const resp = await fetch(healthUrl, { signal: AbortSignal.timeout(5000) })
if (!resp.ok) throw new Error(`HTTP ${resp.status}`)
const data = await resp.json()
@@ -935,6 +942,9 @@ async function testMbe() {
async function testProxy() {
testingProxy.value = true
try {
const isLocalhost = proxyUrl.value.includes('localhost') || proxyUrl.value.includes('127.0.0.1')
// Localhost: direct /health path
// Remote: via reverse proxy at /health (same path)
const healthUrl = `${proxyUrl.value}/health`
const resp = await fetch(healthUrl, { signal: AbortSignal.timeout(5000) })
proxyStatus.value = resp.ok ? 'online' : 'offline'