-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.html
More file actions
72 lines (62 loc) · 2.84 KB
/
Copy pathdebug.html
File metadata and controls
72 lines (62 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>资讯站调试</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-50 min-h-screen p-8">
<h1 class="text-2xl font-bold mb-4">🔧 资讯站调试信息</h1>
<div class="bg-white rounded-lg shadow p-6 mb-6">
<h2 class="text-lg font-semibold mb-2">API 测试</h2>
<pre id="api-result" class="bg-gray-100 p-4 rounded text-sm overflow-auto">测试中...</pre>
</div>
<div class="bg-white rounded-lg shadow p-6">
<h2 class="text-lg font-semibold mb-2">文章列表</h2>
<div id="articles" class="space-y-4">加载中...</div>
</div>
<script>
async function debug() {
const result = document.getElementById('api-result');
const articles = document.getElementById('articles');
try {
// 测试不同URL
const urls = [
'/api/news?limit=5',
'http://127.0.0.1:9000/api/news?limit=5'
];
let output = '';
let html = '';
for (const url of urls) {
try {
const res = await fetch(url);
const data = await res.json();
output += `URL: ${url}\n`;
output += `Success: ${data.success}\n`;
output += `Count: ${data.data?.length || 0}\n`;
output += `First: ${data.data?.[0]?.title?.substring(0, 50) || 'N/A'}...\n\n`;
if (data.data) {
html += `<p class="text-green-600">✅ ${url} 成功,加载 ${data.data.length} 篇</p>`;
data.data.forEach(a => {
html += `<div class="border-l-4 border-blue-500 pl-4 py-2">
<span class="text-xs bg-blue-100 text-blue-800 px-2 py-0.5 rounded">${a.category}</span>
<p class="font-medium">${a.title}</p>
</div>`;
});
}
} catch (e) {
output += `URL: ${url}\nError: ${e.message}\n\n`;
html += `<p class="text-red-600">❌ ${url}: ${e.message}</p>`;
}
}
result.textContent = output;
articles.innerHTML = html;
} catch (e) {
result.textContent = 'Fatal Error: ' + e.message;
}
}
debug();
</script>
</body>
</html>