Files
ARTEX/web/src/proxy.ts
T
Autumn-27andClaude Opus 4.8 0ef8561411 chore: ARTEX 初始化
ARTEX — AI 自主渗透测试系统(Go 后端 + Next.js 前端,单二进制内嵌)。

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-07-26 04:27:45 -04:00

31 lines
1.1 KiB
TypeScript

import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
const AUTH_PAGES = ["/login", "/setup"];
export function proxy(request: NextRequest) {
// Mock demo:无真实登录,放行所有页面(客户端 auth 守卫也会放行)。
if (process.env.NEXT_PUBLIC_MOCK === "1") return NextResponse.next();
const { pathname } = request.nextUrl;
const token = request.cookies.get("artex_token")?.value;
const isAuthPage = AUTH_PAGES.some((p) => pathname === p || pathname.startsWith(`${p}/`));
// 未登录 → 跳转登录页
if (!token && !isAuthPage) {
return NextResponse.redirect(new URL("/login", request.url));
}
// 已登录时访问登录/初始化页 → 跳转主界面
if (token && isAuthPage) {
return NextResponse.redirect(new URL("/function/tasks", request.url));
}
return NextResponse.next();
}
export const config = {
// 跳过 Next.js 内部路由、API 路由、favicon 及 public/ 下的静态文件(含图片、字体等)
matcher: ["/((?!_next/static|_next/image|favicon\\.ico|api/|.*\\.(?:png|jpg|jpeg|gif|webp|svg|ico|woff2?|ttf|otf)$).*)"],
};