Template
1
Fork 0
ip-lookup/app.js
Leonardo Devai 2ecdbbe1f6 Review and modernize all 42 projects to the updated standard
Pinned 2026 toolchains (Go 1.26, Rust 1.98/edition 2024, Python 3.14 + uv, Node 24,
Zig 0.16, NixOS 26.05), postgres 18 / mongo 8, lockfiles built from, non-root
runtimes, .dockerignore, per-project LICENSE, READMEs with the git.devai.io clone
line, checkout@v7 CI. Security fixes in the legacy Rust APIs (any-password login,
self-assigned admin, hard-coded JWT secret), JWT alg/exp/sub enforcement across the
blog series, safe markdown links in the frontends, and many smaller bugs — every
project was built, run and exercised end to end.

Adds scripts/publish.sh + a CI publish job that splits every folder into its own
repo at git.devai.io/templates/<folder>.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01128fhuZbgivaSJvtMf4s1G
2026-09-27 21:10:38 +02:00

58 lines
2 KiB
JavaScript

const statusEl = document.getElementById("status");
const result = document.getElementById("result");
const refresh = document.getElementById("refresh");
// No input at all: ipwho.is looks at the request itself — which IP address it
// came from — and describes that. Whoever opens the page gets their own answer.
async function load() {
statusEl.textContent = "Loading…";
result.hidden = true;
try {
const res = await fetch("https://ipwho.is/");
if (!res.ok) throw new Error(`ipwho.is returned ${res.status}`);
const data = await res.json();
// This API answers 200 even when a lookup fails, and says so INSIDE the
// JSON with success: false. So a good status code isn't enough — check it.
if (data.success === false) {
statusEl.textContent = data.message || "Couldn't look up your address.";
return;
}
render(data);
statusEl.textContent = "";
} catch (err) {
statusEl.textContent = "Something went wrong. Try again in a moment.";
console.error(err);
}
}
// {
// success: true,
// ip: "203.0.113.7",
// city: "Mountain View", region: "California", country: "United States",
// latitude: 37.3861, longitude: -122.0839,
// flag: { emoji: "🇺🇸" },
// connection: { isp: "Google LLC" },
// timezone: { id: "America/Los_Angeles" },
// }
function render(d) {
document.getElementById("ip").textContent = d.ip;
document.getElementById("location").textContent =
[d.city, d.region].filter(Boolean).join(", ") || "Unknown";
document.getElementById("country").textContent = `${d.flag?.emoji || ""} ${d.country}`.trim();
document.getElementById("isp").textContent = d.connection?.isp || "Unknown";
document.getElementById("timezone").textContent = d.timezone?.id || "Unknown";
document.getElementById("map").href =
`https://www.openstreetmap.org/?mlat=${d.latitude}&mlon=${d.longitude}` +
`#map=10/${d.latitude}/${d.longitude}`;
result.hidden = false;
}
refresh.addEventListener("click", load);
load();