Files
MyIP/api/globalping-probes.js
jason5ng32andClaude Opus 5.5 c29e48687b Refactor(layout): split backend-only code out of common/, group frontend utils
common/ had become the backend's library: 30 of its 41 modules were
imported by nothing in the frontend, so the name no longer said what
belonged there. It now holds only what the frontend or the build imports
too; backend-only code moved to server/, flat except for datasets/ (the
dataset engine and its readers). The *-db/ dataset directories stay in
common/: self-hosting docs and Docker volumes mount those paths.

frontend/utils/ keeps its app-wide modules at the root and gains ip/
(IP / ASN shaping and validation), report/ (the report pipeline) and
features/ (the pure layer of a single feature). Paths only — no logic
changes. The Dockerfile copies server/, and the AGENTS.md files say where
a new module goes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 13:10:02 +08:00

29 lines
1.1 KiB
JavaScript

// /api/globalping-probes — compact country inventory of online Globalping
// probes for the frontend country pickers (MtrTest / GlobalLatencyTest /
// CensorshipCheck). Proxying instead of hitting api.globalping.io from the
// browser trades the multi-hundred-KB raw probe list for a few hundred
// bytes, probe-country coverage changes slowly.
import { fetchUpstream } from '../common/fetch-with-timeout.js';
import { buildProbeInventory } from '../server/globalping-inventory.js';
import logger from '../server/logger.js';
const GLOBALPING_PROBES_URL = 'https://api.globalping.io/v1/probes';
export default async (req, res) => {
if (req.method !== 'GET') {
return res.status(405).json({ error: 'Method Not Allowed' });
}
try {
const response = await fetchUpstream(GLOBALPING_PROBES_URL);
if (!response.ok) {
throw new Error(`Globalping probes responded with status ${response.status}`);
}
res.json(buildProbeInventory(await response.json()));
} catch (error) {
logger.error({ err: error }, 'globalping-probes handler failed');
res.status(500).json({ error: error.message });
}
};