fix
This commit is contained in:
@@ -20,7 +20,7 @@ const app = express();
|
|||||||
const PORT = process.env.PORT || 3001;
|
const PORT = process.env.PORT || 3001;
|
||||||
|
|
||||||
// 信任代理,确保正确获取客户端IP地址
|
// 信任代理,确保正确获取客户端IP地址
|
||||||
app.set('trust proxy', true);
|
app.set('trust proxy', '154.17.226.99');
|
||||||
|
|
||||||
// Security middleware
|
// Security middleware
|
||||||
app.use(helmet());
|
app.use(helmet());
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import type { RouteRecordRaw, NavigationGuardNext, RouteLocationNormalized } from 'vue-router'
|
import { createRouter, createWebHistory } from 'vue-router';
|
||||||
import { createRouter, createWebHistory } from 'vue-router'
|
import { useAuthStore } from '@/stores/auth';
|
||||||
import { useAuthStore } from '@/stores/auth'
|
import { adminAuth } from '@/utils/auth';
|
||||||
import { adminAuth } from '@/utils/auth'
|
|
||||||
|
|
||||||
const routes: RouteRecordRaw[] = [
|
const routes = [
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
name: 'Home',
|
name: 'Home',
|
||||||
@@ -58,41 +57,42 @@ const routes: RouteRecordRaw[] = [
|
|||||||
component: () => import('@/views/NotFound.vue'),
|
component: () => import('@/views/NotFound.vue'),
|
||||||
meta: { title: '页面未找到' }
|
meta: { title: '页面未找到' }
|
||||||
}
|
}
|
||||||
]
|
];
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(),
|
history: createWebHistory(),
|
||||||
routes
|
routes,
|
||||||
})
|
});
|
||||||
|
|
||||||
// 路由守卫
|
// 路由守卫
|
||||||
router.beforeEach(async (
|
router.beforeEach((to, from, next) => {
|
||||||
to: RouteLocationNormalized,
|
|
||||||
_from: RouteLocationNormalized,
|
|
||||||
next: NavigationGuardNext
|
|
||||||
) => {
|
|
||||||
// 设置页面标题
|
// 设置页面标题
|
||||||
const title = to.meta.title as string
|
const title = to.meta.title as string;
|
||||||
document.title = `${title} - AI`
|
document.title = `${title} - AI`;
|
||||||
|
|
||||||
|
const authStore = useAuthStore();
|
||||||
|
|
||||||
// 检查是否需要用户认证
|
// 检查是否需要用户认证
|
||||||
if (to.meta.requiresAuth) {
|
if (to.meta.requiresAuth) {
|
||||||
const authStore = useAuthStore()
|
|
||||||
if (!authStore.isLoggedIn) {
|
if (!authStore.isLoggedIn) {
|
||||||
next('/')
|
next('/');
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否需要管理员认证
|
// 检查是否需要管理员认证
|
||||||
if (to.meta.requiresAdminAuth) {
|
if (to.meta.requiresAdminAuth) {
|
||||||
if (!adminAuth.isLoggedIn()) {
|
if (!adminAuth.isLoggedIn()) {
|
||||||
next('/admin/login')
|
next('/admin/login');
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
next('/dashboard')
|
|
||||||
})
|
|
||||||
|
|
||||||
export default router
|
if (to.path === '/' && authStore.isLoggedIn) {
|
||||||
|
return next('/dashboard');
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
||||||
Reference in New Issue
Block a user