flnxi-Wu/lib/tunnel/intranet-module.ts
2026-06-02 19:25:48 +08:00

21 lines
688 B
TypeScript

import { NextResponse } from 'next/server';
type TunnelAction = 'status' | 'start' | 'stop';
function getModuleBaseUrl(): string {
return (process.env.INTRANET_PENETRATION_MODULE_URL || '').trim().replace(/\/+$/, '');
}
export async function proxyIntranetModule(action: TunnelAction): Promise<NextResponse | null> {
const baseUrl = getModuleBaseUrl();
if (!baseUrl) return null;
const method = action === 'status' ? 'GET' : 'POST';
const response = await fetch(`${baseUrl}/${action}`, { method });
const data = await response.json().catch(() => ({
error: '内网穿透模块返回数据异常',
}));
return NextResponse.json(data, { status: response.status });
}