21 lines
684 B
TypeScript
21 lines
684 B
TypeScript
import { NextResponse } from 'next/server';
|
|
|
|
type TunnelAction = 'status' | 'start' | 'stop';
|
|
|
|
function getModuleBaseUrl(): string {
|
|
return (process.env.PAID_CORE_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}/tunnel/${action}`, { method });
|
|
const data = await response.json().catch(() => ({
|
|
error: '内网穿透模块返回数据异常',
|
|
}));
|
|
|
|
return NextResponse.json(data, { status: response.status });
|
|
}
|