40 lines
959 B
TypeScript
40 lines
959 B
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { detectIsIntranet } from '@/lib/network-detection'
|
|
|
|
// GET 只提供前端自动分流所需的内外网判断,不返回代理头或客户端 IP 明细。
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const isIntranet = detectIsIntranet(request)
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
isIntranet,
|
|
timestamp: new Date().toISOString(),
|
|
}, {
|
|
headers: { 'Cache-Control': 'no-store' },
|
|
})
|
|
} catch (error) {
|
|
console.error('[Network Status] Error:', error)
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: '网络检测失败'
|
|
},
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|
|
|
|
export async function POST() {
|
|
return NextResponse.json(
|
|
{ error: '该接口仅支持网络状态查询' },
|
|
{
|
|
status: 405,
|
|
headers: {
|
|
Allow: 'GET',
|
|
'Cache-Control': 'no-store',
|
|
},
|
|
},
|
|
)
|
|
}
|