feat: 合并后台到主服务端口19004

- 后台管理整合到 /admin 路径
- 前台保持原有路由
- 统一API路径(后台 /admin/api/xxx)
- 删除独立admin服务(保留admin目录作为模板)
- 简化部署,只需启动一个服务
This commit is contained in:
2026-04-12 17:05:01 +08:00
parent cb4b7d5363
commit 47bf6f48d5
3 changed files with 328 additions and 21 deletions

View File

@@ -21,23 +21,26 @@
</h1>
</div>
<nav class="mt-6">
<a href="/" class="flex items-center gap-3 px-6 py-3 bg-slate-700 text-white">
<a href="/admin" class="flex items-center gap-3 px-6 py-3 bg-slate-700 text-white">
<i class="ri-dashboard-line"></i><span>仪表盘</span>
</a>
<a href="/users" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<a href="/admin/users" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-user-line"></i><span>用户管理</span>
</a>
<a href="/posts" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<a href="/admin/posts" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-file-text-line"></i><span>帖子管理</span>
</a>
<a href="/topics" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<a href="/admin/topics" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-tools-line"></i><span>主题管理</span>
</a>
</nav>
<div class="absolute bottom-0 left-0 right-0 p-4 border-t border-slate-700">
<a href="http://localhost:19004" target="_blank" class="text-slate-400 hover:text-white text-sm flex items-center gap-2">
<a href="/" target="_blank" class="text-slate-400 hover:text-white text-sm flex items-center gap-2">
<i class="ri-external-link-line"></i> 访问前台
</a>
<button onclick="logout()" class="mt-2 text-slate-400 hover:text-red-400 text-sm flex items-center gap-2">
<i class="ri-logout-box-line"></i> 退出登录
</button>
</div>
</aside>
@@ -140,8 +143,24 @@
</div>
<script>
// 检查登录状态
async function checkAuth() {
const res = await fetch('/admin/api/check-auth');
const data = await res.json();
if (!data.logged_in) {
window.location.href = '/admin/login';
}
}
checkAuth();
// 退出登录
async function logout() {
await fetch('/admin/api/logout', { method: 'POST' });
window.location.href = '/admin/login';
}
async function loadStats() {
const res = await fetch('/api/stats');
const res = await fetch('/admin/api/stats');
const data = await res.json();
document.getElementById('stat-users').textContent = data.users_count;
@@ -155,7 +174,7 @@
}
async function loadTags() {
const res = await fetch('/api/tags');
const res = await fetch('/admin/api/tags');
const tags = await res.json();
const container = document.getElementById('tagsList');
@@ -172,7 +191,7 @@
}
async function loadRecentPosts() {
const res = await fetch('/api/posts');
const res = await fetch('/admin/api/posts');
const posts = await res.json();
const container = document.getElementById('recentPosts');

View File

@@ -98,7 +98,7 @@
const data = await res.json();
if (data.success) {
window.location.href = '/';
window.location.href = '/admin';
} else {
errorEl.textContent = data.error || '登录失败';
errorEl.classList.remove('hidden');
@@ -113,4 +113,4 @@
});
</script>
</body>
</html>
</html>>