添加管理员登陆,添加nginx反向代理配置,

This commit is contained in:
2025-07-27 20:01:36 +08:00
parent 9a366d042a
commit 33363aba78
17 changed files with 2010 additions and 836 deletions
+28 -2
View File
@@ -29,6 +29,7 @@ import LoadingBarContainer from "~/components/ui/LoadingBar";
import RouteChangeLoader from "~/components/ui/RouteChangeLoader";
// import { useState, useEffect } from "react";
// 导入认证相关的服务器端功能(仅在服务器端使用)
import {
getUserSession,
@@ -70,7 +71,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
const pathname = url.pathname;
// 排除不需要登录验证的路径
const publicPaths = ['/login', '/favicon.ico'];
const publicPaths = ['/login', '/favicon.ico', '/callback'];
const isPublicPath = publicPaths.some(path => pathname.startsWith(path));
// 获取用户会话(可能包含刷新后的token)
@@ -108,6 +109,31 @@ export async function loader({ request }: LoaderFunctionArgs) {
return redirect("/");
}
// 检查5178端口访问控制
// 由于应用直接运行在5178端口,我们需要从环境变量或运行时获取端口
const currentPort = process.env.PORT || process.env.API_PORT_CONFIG;
// console.log("currentPort-----------",currentPort)
// 获取运行时端口(从请求URL或环境变量)
const runtimePort = url.port || currentPort;
// console.log("runtimePort-----------",runtimePort)
const isPort51708 = currentPort === '5178' || runtimePort === '5178';
if (isPort51708 && !isPublicPath) {
// 51708端口只允许访问交叉评查相关路径和首页
const allowedPaths = ['/', '/cross-checking','/chat-with-llm'];
const isAllowedPath = allowedPaths.some(path => pathname === path) ||
pathname.startsWith('/cross-checking/') ||
pathname.startsWith('/chat-with-llm/');
if (!isAllowedPath) {
// console.log("5178端口访问受限,重定向到交叉评查页面");
return redirect("/cross-checking");
}
}
// 如果token被刷新了,需要在响应中设置更新后的cookie
const responseHeaders: Record<string, string> = {};
if (refreshedSession) {
@@ -237,4 +263,4 @@ export function ErrorBoundary() {
</body>
</html>
);
}
}