From 8a8bbd1b71ee9568fa95b2181c58ebb57cfab2e5 Mon Sep 17 00:00:00 2001 From: Unchained Date: Tue, 31 Mar 2026 08:18:20 +0200 Subject: [PATCH] fix(analytics): create actual route handler for OpenPanel track endpoint The standalone build doesn't support rewrites - need actual route handler to proxy OpenPanel API requests. --- next.config.ts | 4 --- src/app/api/op/track/route.ts | 65 +++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 src/app/api/op/track/route.ts diff --git a/next.config.ts b/next.config.ts index 48c54db..a8d2bf3 100644 --- a/next.config.ts +++ b/next.config.ts @@ -34,10 +34,6 @@ const nextConfig: NextConfig = { source: "/api/op/track", destination: `${openpanelUrl}/track`, }, - { - source: "/api/op/track/:path*", - destination: `${openpanelUrl}/track/:path*`, - }, ]; }, images: { diff --git a/src/app/api/op/track/route.ts b/src/app/api/op/track/route.ts new file mode 100644 index 0000000..edb63a4 --- /dev/null +++ b/src/app/api/op/track/route.ts @@ -0,0 +1,65 @@ +import { NextRequest, NextResponse } from "next/server"; + +const OPENPANEL_API_URL = process.env.OPENPANEL_API_URL || "https://op.nodecrew.me/api"; + +export async function POST(request: NextRequest) { + try { + const body = await request.text(); + const headers: Record = { + "Content-Type": "application/json", + "openpanel-client-id": process.env.NEXT_PUBLIC_OPENPANEL_CLIENT_ID || "", + }; + + if (process.env.OPENPANEL_CLIENT_SECRET) { + headers["openpanel-client-secret"] = process.env.OPENPANEL_CLIENT_SECRET; + } + + const response = await fetch(`${OPENPANEL_API_URL}/track`, { + method: "POST", + headers, + body, + }); + + const data = await response.text(); + return new NextResponse(data, { + status: response.status, + headers: { + "Content-Type": "application/json", + "Access-Control-Allow-Origin": "*", + }, + }); + } catch (error) { + console.error("[OpenPanel Proxy] Error:", error); + return new NextResponse(JSON.stringify({ error: "Proxy error" }), { + status: 500, + }); + } +} + +export async function GET(request: NextRequest) { + const url = new URL(request.url); + const path = url.searchParams.get("path") || ""; + + try { + const response = await fetch(`${OPENPANEL_API_URL}/track/${path}`, { + method: "GET", + headers: { + "openpanel-client-id": process.env.NEXT_PUBLIC_OPENPANEL_CLIENT_ID || "", + }, + }); + + const data = await response.text(); + return new NextResponse(data, { + status: response.status, + headers: { + "Content-Type": "application/json", + "Access-Control-Allow-Origin": "*", + }, + }); + } catch (error) { + console.error("[OpenPanel Proxy] Error:", error); + return new NextResponse(JSON.stringify({ error: "Proxy error" }), { + status: 500, + }); + } +}