feat(proxy): add proxy pool and per-connection binding + strictProxy support

- Centralize proxy management with reusable proxy pools
- Per-connection proxy binding with legacy fallback
- Add strictProxy option: fail hard instead of silently falling back to direct
- Resolve alicode-intl conflict: keep alicode-intl support + proxy support

Made-with: Cursor
This commit is contained in:
decolua committed 2026-03-09 15:46:06 +07:00
1 parent 4c469291a1
commit 880f4eca91
22 files changed
+1811 -146

No files matched your search

@@ -0,0 +1,37 @@
import { NextResponse } from "next/server";
import { getProxyPoolById, updateProxyPool } from "@/models";
import { testProxyUrl } from "@/lib/network/proxyTest";
// POST /api/proxy-pools/[id]/test - Test proxy pool entry
export async function POST(request, { params }) {
try {
const { id } = await params;
const proxyPool = await getProxyPoolById(id);
if (!proxyPool) {
return NextResponse.json({ error: "Proxy pool not found" }, { status: 404 });
}
const result = await testProxyUrl({ proxyUrl: proxyPool.proxyUrl });
const now = new Date().toISOString();
await updateProxyPool(id, {
testStatus: result.ok ? "active" : "error",
lastTestedAt: now,
lastError: result.ok ? null : (result.error || `Proxy test failed with status ${result.status}`),
isActive: result.ok,
});
return NextResponse.json({
ok: result.ok,
status: result.status,
statusText: result.statusText || null,
error: result.error || null,
elapsedMs: result.elapsedMs || 0,
testedAt: now,
});
} catch (error) {
console.log("Error testing proxy pool:", error);
return NextResponse.json({ error: "Failed to test proxy pool" }, { status: 500 });
}
}