修復 too many connection 問題

This commit is contained in:
2025-09-21 02:46:16 +08:00
parent a36ab3c98d
commit 808d5bb52c
36 changed files with 5582 additions and 249 deletions

View File

@@ -0,0 +1,78 @@
// =====================================================
// 手動設置客戶端 IP API
// =====================================================
import { NextRequest, NextResponse } from 'next/server';
import { smartIPPool } from '@/lib/smart-ip-connection-pool';
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { clientIP } = body;
if (!clientIP) {
return NextResponse.json({
success: false,
error: '缺少客戶端 IP 參數'
}, { status: 400 });
}
console.log('🔧 手動設置客戶端 IP:', clientIP);
// 設置客戶端 IP
smartIPPool.setClientIP(clientIP);
return NextResponse.json({
success: true,
message: `客戶端 IP 已設置為: ${clientIP}`,
data: {
clientIP,
timestamp: new Date().toISOString()
}
});
} catch (error) {
console.error('❌ 設置客戶端 IP 失敗:', error);
return NextResponse.json({
success: false,
error: '設置客戶端 IP 失敗',
details: error instanceof Error ? error.message : '未知錯誤'
}, { status: 500 });
}
}
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const clientIP = searchParams.get('ip');
if (!clientIP) {
return NextResponse.json({
success: false,
error: '缺少 IP 參數'
}, { status: 400 });
}
console.log('🔧 通過 GET 設置客戶端 IP:', clientIP);
// 設置客戶端 IP
smartIPPool.setClientIP(clientIP);
return NextResponse.json({
success: true,
message: `客戶端 IP 已設置為: ${clientIP}`,
data: {
clientIP,
timestamp: new Date().toISOString()
}
});
} catch (error) {
console.error('❌ 設置客戶端 IP 失敗:', error);
return NextResponse.json({
success: false,
error: '設置客戶端 IP 失敗',
details: error instanceof Error ? error.message : '未知錯誤'
}, { status: 500 });
}
}