fix(analytics): use route handler for OpenPanel script to fix query param issue
Some checks failed
Build and Deploy / build (push) Has been cancelled

This commit is contained in:
Unchained
2026-03-31 07:19:14 +02:00
parent ff629691a5
commit cee3b71454
3 changed files with 26 additions and 6 deletions

View File

@@ -34,10 +34,6 @@ const nextConfig: NextConfig = {
source: "/api/op/track",
destination: `${openpanelUrl}/track`,
},
{
source: "/api/op/op1.js",
destination: `${openpanelScriptUrl}/op1.js`,
},
];
},
images: {

View File

@@ -54,8 +54,8 @@ export default async function LocaleLayout({
clientId={process.env.NEXT_PUBLIC_OPENPANEL_CLIENT_ID || ""}
trackScreenViews={true}
trackOutgoingLinks={true}
apiUrl="/api/op"
scriptUrl="/api/op/op1.js"
apiUrl="/api/op/track"
scriptUrl="/api/op1"
/>
<Script
src="/api/script.js"

24
src/app/api/op1/route.ts Normal file
View File

@@ -0,0 +1,24 @@
import { NextResponse } from "next/server";
const OPENPANEL_SCRIPT_URL = "https://op.nodecrew.me/op1.js";
export async function GET(request: Request) {
const url = new URL(request.url);
const searchParams = url.search;
try {
const response = await fetch(`${OPENPANEL_SCRIPT_URL}${searchParams}`);
const content = await response.text();
return new NextResponse(content, {
status: 200,
headers: {
"Content-Type": "application/javascript",
"Cache-Control": "public, max-age=86400, stale-while-revalidate=86400",
},
});
} catch (error) {
console.error("[OpenPanel] Failed to fetch script:", error);
return new NextResponse("/* OpenPanel script unavailable */", { status: 500 });
}
}