Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
/**
* Reverse-proxy handler for embedded service UIs.
*
* Route: /dashboard/providers/services/[name]/embed/[[...path]]
*
* Optional catch-all ([[...path]]) so the segment-less prefix
* `/embed/` (the panel root — #6205) also matches; a required catch-all
* ([...path]) does not match a zero-segment path and falls through to 404.
*
* Thin wrapper — all proxy logic lives in @/lib/services/reverseProxy.ts.
*
* Security:
* - Target URL is constructed from the service's registered port — never
* from user input — eliminating SSRF risk.
* - The route is classified LOCAL_ONLY in routeGuard.ts; the management
* policy blocks all non-loopback access before this handler runs.
* - See reverseProxy.ts for full security documentation.
*/
import { proxyRequest } from "@/lib/services/reverseProxy";
export const dynamic = "force-dynamic";
// Optional catch-all: `path` is `undefined` for the segment-less `/embed/` root.
type RouteParams = { name: string; path?: string[] };
async function handleProxy(request: Request, params: RouteParams): Promise<Response> {
const { name, path } = params;
return proxyRequest(request, path ?? [], {
name,
publicPrefix: `/dashboard/providers/services/${name}/embed`,
htmlRewrite: true,
});
}
export async function GET(
request: Request,
{ params }: { params: Promise<RouteParams> }
): Promise<Response> {
return handleProxy(request, await params);
}
export async function POST(
request: Request,
{ params }: { params: Promise<RouteParams> }
): Promise<Response> {
return handleProxy(request, await params);
}
export async function PUT(
request: Request,
{ params }: { params: Promise<RouteParams> }
): Promise<Response> {
return handleProxy(request, await params);
}
export async function PATCH(
request: Request,
{ params }: { params: Promise<RouteParams> }
): Promise<Response> {
return handleProxy(request, await params);
}
export async function DELETE(
request: Request,
{ params }: { params: Promise<RouteParams> }
): Promise<Response> {
return handleProxy(request, await params);
}
export async function HEAD(
request: Request,
{ params }: { params: Promise<RouteParams> }
): Promise<Response> {
return handleProxy(request, await params);
}
export async function OPTIONS(
request: Request,
{ params }: { params: Promise<RouteParams> }
): Promise<Response> {
return handleProxy(request, await params);
}