40 lines
1.4 KiB
JavaScript
40 lines
1.4 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const BASE_URL = "http://localhost:9551/api/contents/update";
|
|
|
|
function truncateText(text, maxLen = 256) {
|
|
if (typeof text !== "string") return "";
|
|
return text.length > maxLen ? text.slice(0, maxLen) : text;
|
|
}
|
|
|
|
async function requestLatest() {
|
|
const url = `${BASE_URL}?date=latest`;
|
|
try {
|
|
const res = await fetch(url, { method: "GET" });
|
|
const text = await res.text().catch(() => "");
|
|
if (!res.ok) {
|
|
const preview = truncateText(text, 256);
|
|
console.error(`[FAIL] latest | ${url} -> ${res.status} ${res.statusText} ${preview ? `| ${preview}` : ""}`);
|
|
return { ok: false, status: res.status, body: text };
|
|
}
|
|
const preview = truncateText(text, 256);
|
|
console.log(`[OK] latest | ${url} -> ${preview || res.status}`);
|
|
return { ok: true, status: res.status, body: text };
|
|
} catch (err) {
|
|
const errMsg = err instanceof Error ? err.message : String(err);
|
|
console.error(`[ERROR] latest | ${url} -> ${truncateText(errMsg, 256)}`);
|
|
return { ok: false, error: err };
|
|
}
|
|
}
|
|
|
|
// Node 18+ 환경 가정: fetch 전역 제공. 없으면 종료 안내.
|
|
if (typeof fetch !== "function") {
|
|
console.error("현재 Node 런타임에 fetch가 없습니다. Node 18+를 사용하거나 폴리필을 추가하세요.");
|
|
process.exit(1);
|
|
}
|
|
|
|
requestLatest().catch((err) => {
|
|
console.error("예상치 못한 오류:", err);
|
|
process.exit(1);
|
|
});
|