From 9bc42496f582e11c553ad705a14dd3e2de4c3b06 Mon Sep 17 00:00:00 2001 From: bluish <734499798@qq.com> Date: Mon, 21 Jul 2025 22:50:36 +0800 Subject: [PATCH] revert 3e4f9ad6604f7cf2201fdc40c9158cf59fd76074 revert fix --- backend/src/index.ts | 2 +- frontend/src/router/index.ts | 46 ++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/backend/src/index.ts b/backend/src/index.ts index 4125504..5472516 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -20,7 +20,7 @@ const app = express(); const PORT = process.env.PORT || 3001; // 信任代理,确保正确获取客户端IP地址 -app.set('trust proxy', '154.17.226.99'); +app.set('trust proxy', true); // Security middleware app.use(helmet()); diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 334423f..f5aceab 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -1,8 +1,9 @@ -import { createRouter, createWebHistory } from 'vue-router'; -import { useAuthStore } from '@/stores/auth'; -import { adminAuth } from '@/utils/auth'; +import type { RouteRecordRaw, NavigationGuardNext, RouteLocationNormalized } from 'vue-router' +import { createRouter, createWebHistory } from 'vue-router' +import { useAuthStore } from '@/stores/auth' +import { adminAuth } from '@/utils/auth' -const routes = [ +const routes: RouteRecordRaw[] = [ { path: '/', name: 'Home', @@ -57,42 +58,41 @@ const routes = [ component: () => import('@/views/NotFound.vue'), meta: { title: '页面未找到' } } -]; +] const router = createRouter({ history: createWebHistory(), - routes, -}); + routes +}) // 路由守卫 -router.beforeEach((to, from, next) => { +router.beforeEach(async ( + to: RouteLocationNormalized, + _from: RouteLocationNormalized, + next: NavigationGuardNext +) => { // 设置页面标题 - const title = to.meta.title as string; - document.title = `${title} - AI`; - - const authStore = useAuthStore(); + const title = to.meta.title as string + document.title = `${title} - AI` // 检查是否需要用户认证 if (to.meta.requiresAuth) { + const authStore = useAuthStore() if (!authStore.isLoggedIn) { - next('/'); - return; + next('/') + return } } // 检查是否需要管理员认证 if (to.meta.requiresAdminAuth) { if (!adminAuth.isLoggedIn()) { - next('/admin/login'); - return; + next('/admin/login') + return } } - if (to.path === '/' && authStore.isLoggedIn) { - return next('/dashboard'); - } + next('/dashboard') +}) - next(); -}); - -export default router; \ No newline at end of file +export default router \ No newline at end of file