// 临时预览服务:http://localhost:8787 -> 列出 reports/ 下所有 html
const http = require('http');
const fs = require('fs');
const path = require('path');
const ROOT = path.join(process.cwd(), 'reports');
const PORT = 8787;
function buildIndex() {
const files = fs.readdirSync(ROOT).filter((f) => f.endsWith('.html'));
const links = files.map((f) => {
const size = (fs.statSync(path.join(ROOT, f)).size / 1024).toFixed(1);
return `📄 ${f} ${size}KB`;
}).join('');
return `
VOC Reports
📊 VOC 报告(含 TikTok 海外阵地 slide)
Total slides per report: 12 (基础 10 + TikTok + 抖音)
${links}
TikTok slide 关键字:
· liver → milk thistle / liver cleanse detox / silymarin / liver support supplement
· probiotic → kids probiotics / children probiotics gummy / probiotics gummies for kids / daily probiotic for kids
· monkey → lions mane mushroom supplement / lion mane mushroom / stomach gut health supplement / lions mane gummies
`;
}
http.createServer((req, res) => {
const url = decodeURIComponent((req.url || '/').split('?')[0]);
if (url === '/' || url === '/index.html') {
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
res.end(buildIndex());
return;
}
const fp = path.join(ROOT, url.replace(/^\/+/, ''));
if (!fp.startsWith(ROOT) || !fs.existsSync(fp)) {
res.writeHead(404); res.end('Not Found'); return;
}
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
fs.createReadStream(fp).pipe(res);
}).listen(PORT, () => console.log('Preview server → http://localhost:' + PORT));