Add authenticated LAN access, native Claude execution, checkpoint and budget recovery, and signed POC build/deploy/rollback contracts. Include local service management, regression coverage, and evidence from the completed POC delivery.
29 lines
1.3 KiB
TypeScript
29 lines
1.3 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getSession } from './lib/auth';
|
|
import { localAccessEnabled, localRequestAllowed, localRequestOrigin } from './lib/local-access';
|
|
|
|
/** Local access is opt-in. Production OIDC continues to use its existing route/session flow. */
|
|
export async function proxy(request: NextRequest) {
|
|
if (!localAccessEnabled()) return NextResponse.next();
|
|
if (!localRequestAllowed(request))
|
|
return NextResponse.json({ error: { code: 'ORIGIN_DENIED', message: '请求来源不被允许。' } }, { status: 403 });
|
|
const path = request.nextUrl.pathname;
|
|
if (path === '/login' || path.startsWith('/_next/static/') || path === '/icon.svg') return NextResponse.next();
|
|
const session = await getSession(request);
|
|
if (session) {
|
|
const response = NextResponse.next();
|
|
response.headers.set('Cache-Control', 'no-store');
|
|
return response;
|
|
}
|
|
if (path.startsWith('/api/'))
|
|
return NextResponse.json(
|
|
{ error: { code: 'UNAUTHENTICATED', message: '请先登录本机工作空间。' } },
|
|
{ status: 401, headers: { 'Cache-Control': 'no-store' } },
|
|
);
|
|
const login = new URL('/login', localRequestOrigin(request));
|
|
login.searchParams.set('returnTo', `${path}${request.nextUrl.search}`);
|
|
return NextResponse.redirect(login);
|
|
}
|
|
|
|
export const config = { matcher: ['/:path*'] };
|