feat : 클라우드플레어 워커 코드 저장소에 추가, NAS 꺼짐(00~07시) 공지 화면 (사이트 터미널 색 적용)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
headporterandClaude Opus 5.5 committed 2026-11-30 14:14:04 +09:00
1 parent bee2ac9153
commit 0b9dcafa19
2 files changed
+134 -1

No files matched your search

+133
View File
@@ -0,0 +1,133 @@
// Cloudflare Worker "specialsource-router" 코드 (대시보드 → Workers & Pages → specialsource-router → 코드 편집에 통째로 붙여 넣고 배포)
// www·루트 도메인 요청을 NAS로 그대로 전달. NAS가 꺼져 있으면(밤 0~7시 전원 차단, 장애) 공지 화면을 대신 보여 줌
// ※ 시간 제한(타임아웃)을 걸지 말 것: 큰 업로드가 중간에 끊김 (2026-11-30 업로드 500 오류 원인)
const NAS_HOST = "nas-direct.specialsource.company";
const router = {
async fetch(request) {
const url = new URL(request.url);
url.hostname = NAS_HOST;
try {
const res = await fetch(new Request(url, request));
// 502~504: NAS 프록시 매니저가 뒤쪽 서버에 못 붙음, 520~530: 클라우드플레어가 NAS에 못 붙음
const down = (res.status >= 502 && res.status <= 504) || (res.status >= 520 && res.status <= 530);
return down ? offline(url) : res;
} catch {
return offline(url);
}
},
};
export default router;
function offline(url) {
const headers = { "Retry-After": "600", "Cache-Control": "no-store" };
// API 요청은 JSON으로 → 사이트 화면이 열려 있던 사람에게도 이유가 보임
if (url.pathname.startsWith("/api/")) {
return Response.json({ error: "서버가 쉬는 중입니다 (매일 00:00~07:00). 7시 이후에 다시 시도하세요." }, { status: 503, headers });
}
return new Response(NOTICE_HTML, { status: 503, headers: { ...headers, "Content-Type": "text/html; charset=utf-8" } });
}
// 공지 화면 (1번 시안: 파랑 PC통신). 색은 사이트에서 고른 터미널 색(localStorage "bbs-palette")을 따름
// ※ 이 문자열 안에서는 백틱(`)과 ${ 를 쓰지 말 것 (템플릿 문자열이 깨짐)
const NOTICE_HTML = `<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex">
<title>SPECIALSOURCE · 서버 취침 중</title>
<script>try{document.documentElement.dataset.palette=localStorage.getItem("bbs-palette")||""}catch(e){}</script>
<style>
:root, html[data-palette="blue"] {
--bg: #0000a8; --fg: #c0c0c0; --hi: #ffffff; --accent: #55ffff;
--highlight: #ffff55; --dim: #8080d0; --bar: #00a8a8; --bar-fg: #000000;
}
html[data-palette="green"] {
--bg: #001400; --fg: #33ff66; --hi: #b8ffc8; --accent: #66ff99;
--highlight: #ccff66; --dim: #1f8f3f; --bar: #33ff66; --bar-fg: #000000;
}
html[data-palette="amber"] {
--bg: #140a00; --fg: #ffb000; --hi: #ffe0a0; --accent: #ffcc55;
--highlight: #ffffff; --dim: #a06a00; --bar: #ffb000; --bar-fg: #000000;
}
:root { --mono: "D2Coding", "Cascadia Mono", "JetBrains Mono", Consolas, ui-monospace, monospace; color-scheme: dark; }
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
background: var(--bg); color: var(--fg); font: clamp(14px, 1.1vw + 6px, 19px)/1.6 var(--mono);
display: grid; grid-template-rows: auto 1fr auto; position: relative; overflow: hidden;
}
body::after {
content: ""; position: fixed; inset: 0; pointer-events: none;
background: repeating-linear-gradient(transparent 0 2px, rgba(0,0,0,.18) 2px 3px),
radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,.45));
}
.status, .keys {
display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 2ch;
background: var(--bar); color: var(--bar-fg); font-weight: 700;
padding: 0 max(16px, env(safe-area-inset-left));
}
main { display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left)); min-height: 0; }
.win { border: 4px double var(--fg); padding: 1.2em 2ch 1.4em; width: min(64ch, 100%); position: relative; }
.cap { position: absolute; top: -.85em; left: 2ch; background: var(--bg); color: var(--highlight); padding: 0 1ch; font-weight: 700; }
h1 { margin: .2em 0 .6em; color: var(--hi); font-size: 1.5em; letter-spacing: .05em; }
p { margin: 0 0 .8em; }
b { color: var(--hi); }
dl { display: grid; grid-template-columns: auto 1fr; gap: .2em 2ch; margin: 1em 0; }
dt { color: var(--accent); } dd { margin: 0; color: var(--hi); }
.left { color: var(--highlight); font-size: 1.6em; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .08em; }
.bar { color: var(--accent); white-space: pre; overflow: hidden; }
.dim { color: var(--dim); }
.blink { animation: b 1s steps(1) infinite; } @keyframes b { 50% { opacity: 0; } }
button { font: inherit; background: none; border: 0; color: var(--bar-fg); font-weight: 700; cursor: pointer; padding: 0; }
button:focus-visible { outline: 2px solid var(--highlight); }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { .blink { animation: none; } }
</style>
</head>
<body>
<div class="status"><span>SPECIALSOURCE BBS</span><span>접속 대기</span><span id="now">--:--:--</span></div>
<main>
<section class="win">
<span class="cap">═ 공지 ═</span>
<div id="night">
<h1>서버 취침 중<span class="blink">_</span></h1>
<p>전기료를 아끼려고 매일 <b>밤 12시부터 아침 7시까지</b> 서버 전원을 끕니다.</p>
<p>7시가 되면 자동으로 켜지니, 그때 다시 접속해 주세요.</p>
<dl>
<dt>쉬는 시간</dt><dd>00:00 ~ 07:00 (한국 시간)</dd>
<dt>재가동까지</dt><dd class="left" id="left">--:--:--</dd>
</dl>
<div class="bar" id="bar">░░░░░░░░░░░░░░░░░░░░</div>
<div class="dim">00시 ──────────────── 07시</div>
</div>
<div id="day" hidden>
<h1>서버 연결 안 됨<span class="blink">_</span></h1>
<p>지금은 서버에 연결할 수 없습니다. 아침에 켜지는 중이거나 점검 중일 수 있어요.</p>
<p>잠시 후 <b>F5</b>를 눌러 다시 시도해 주세요.</p>
</div>
</section>
</main>
<div class="keys"><span>NAS 전원 꺼짐</span><button type="button" onclick="location.reload()">F5 새로고침</button><span>07:00 자동 재가동</span></div>
<script>
// 한국 시간 기준. 0~7시면 재가동까지 남은 시간, 그 밖의 시간에 꺼져 있으면 장애 안내
var H = 3600e3;
function pad(n) { return String(n).padStart(2, "0"); }
function fmt(ms) { return pad(Math.floor(ms / H)) + ":" + pad(Math.floor(ms / 6e4) % 60) + ":" + pad(Math.floor(ms / 1e3) % 60); }
function tick() {
var kst = Date.now() + 9 * H, day = Math.floor(kst / (24 * H)) * 24 * H, wake = day + 7 * H;
var sleeping = kst < wake;
document.getElementById("now").textContent = fmt(kst - day);
document.getElementById("night").hidden = !sleeping;
document.getElementById("day").hidden = sleeping;
if (!sleeping) return;
var left = wake - kst, done = 1 - left / (7 * H), n = Math.round(done * 20);
document.getElementById("left").textContent = fmt(left);
document.getElementById("bar").textContent = "▓".repeat(n) + "░".repeat(20 - n) + " " + Math.round(done * 100) + "%";
}
tick(); setInterval(tick, 1000);
</script>
</body>
</html>`;