1
Fork 0
nasa-photo-proxy/public/app.js
Leonardo Devai f4fa0aa5e1 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

44 lines
1.4 KiB
JavaScript

// This page asks "/api/apod" — its OWN server — never nasa.gov. The browser
// never sees the API key; that's the whole point of having a backend.
const statusEl = document.getElementById("status");
const figure = document.getElementById("figure");
const image = document.getElementById("image");
const reloadBtn = document.getElementById("reload");
async function loadPhoto() {
statusEl.textContent = "Loading today's photo…";
statusEl.hidden = false;
figure.hidden = true;
let res;
try {
res = await fetch("/api/apod");
} catch (err) {
statusEl.textContent = "Could not reach the server. Is it running?";
console.error(err);
return;
}
const data = await res.json().catch(() => ({}));
if (!res.ok) {
statusEl.textContent = data.error || `The server answered ${res.status}.`;
return;
}
if (!data.image) {
statusEl.textContent = `Today's entry ("${data.title}") is a video, not a photo. Try again tomorrow!`;
return;
}
image.src = data.image;
image.alt = data.title;
document.getElementById("title").textContent = data.title;
document.getElementById("date").textContent = data.date;
document.getElementById("explanation").textContent = data.explanation;
document.getElementById("credit").textContent = data.credit ? `© ${data.credit}` : "Public domain (NASA)";
statusEl.hidden = true;
figure.hidden = false;
}
reloadBtn.addEventListener("click", loadPhoto);
loadPhoto();