여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다. - ts·tsx·js·mjs·css·py 478개: 여러 줄 주석은 첫 문장 한 줄로, 과거형·날짜 문장은 삭제 - 주석 위치는 TypeScript 파서·파이썬 tokenize/ast 로 찾는다 — 문자열 안의 # · /* 는 건드리지 않는다 - eslint·ts·noqa·type: ignore 같은 지시 주석은 그대로 둔다 파이썬 275개 정리 전후 AST 동일, TS 298개 주석 뺀 토큰 동일(빈 JSX 주석 10곳만 차이). site·frontend·admin tsc, site vitest 105 passed Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
44 lines
1.6 KiB
JavaScript
44 lines
1.6 KiB
JavaScript
/** 발행 사이트 정적 서버. */
|
|
import {createReadStream, existsSync, statSync} from 'node:fs';
|
|
import {createServer} from 'node:http';
|
|
import {dirname, extname, join, normalize, resolve} from 'node:path';
|
|
import {fileURLToPath} from 'node:url';
|
|
|
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
const OUT = resolve(HERE, '..', 'out');
|
|
const PORT = Number(process.env.PORT ?? 3001);
|
|
|
|
const MIME = {
|
|
'.html': 'text/html; charset=utf-8',
|
|
'.js': 'text/javascript; charset=utf-8',
|
|
'.css': 'text/css; charset=utf-8',
|
|
'.json': 'application/json; charset=utf-8',
|
|
'.xml': 'application/xml; charset=utf-8',
|
|
'.txt': 'text/plain; charset=utf-8',
|
|
'.woff2': 'font/woff2',
|
|
'.svg': 'image/svg+xml',
|
|
'.png': 'image/png',
|
|
'.jpg': 'image/jpeg',
|
|
};
|
|
|
|
createServer((req, res) => {
|
|
// 한글 슬러그가 퍼센트 인코딩으로 오므로 반드시 디코드한다.
|
|
const raw = decodeURIComponent((req.url ?? '/').split('?')[0]);
|
|
// 경로 탈출(../) 차단 — 정적 서버의 기본 안전장치다.
|
|
const rel = normalize(raw).replace(/^(\.\.[/\\])+/, '');
|
|
let file = join(OUT, rel);
|
|
|
|
if (existsSync(file) && statSync(file).isDirectory()) file = join(file, 'index.html');
|
|
|
|
if (!existsSync(file)) {
|
|
res.writeHead(404, {'Content-Type': 'text/html; charset=utf-8'});
|
|
res.end('<h1>404</h1><p>발행된 사이트가 없습니다. 발행 후 자동으로 생성됩니다.</p>');
|
|
return;
|
|
}
|
|
|
|
res.writeHead(200, {'Content-Type': MIME[extname(file)] ?? 'application/octet-stream'});
|
|
createReadStream(file).pipe(res);
|
|
}).listen(PORT, () => {
|
|
console.log(`[serve] 발행 사이트 → http://localhost:${PORT}/s/<주소>`);
|
|
});
|