mirror of
https://github.com/jason5ng32/MyIP.git
synced 2026-11-04 08:55:47 +00:00
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>
35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
// /api/ipapi — geolocation source handler backed by ip-api.com.
|
|
// Forwards the optional ?lang and normalizes the response into the
|
|
// canonical geo shape via the shared makeGeoHandler factory.
|
|
|
|
import { makeGeoHandler } from '../server/geo-handler.js';
|
|
|
|
function buildUrl(req) {
|
|
const ipAddress = req.query.ip;
|
|
|
|
// Build request URL for ip-api.com
|
|
const lang = req.query.lang || 'en';
|
|
const url = `http://ip-api.com/json/${ipAddress}?fields=66842623&lang=${lang}`;
|
|
return { url, logContext: { lang } };
|
|
}
|
|
|
|
function modifyJsonForIPAPI(json) {
|
|
const { query, country, countryCode, regionName, city, lat, lon, isp, as } = json;
|
|
const asn = as ? as.split(" ")[0] : '';
|
|
|
|
return {
|
|
ip: query,
|
|
city,
|
|
region: regionName,
|
|
country: countryCode,
|
|
country_name: country,
|
|
country_code: countryCode,
|
|
latitude: lat,
|
|
longitude: lon,
|
|
asn,
|
|
org: isp
|
|
};
|
|
}
|
|
|
|
export default makeGeoHandler({ name: 'ipapi-com', buildUrl, normalize: modifyJsonForIPAPI });
|