fix: add OpenPanel proxy routes for script and tracking

This commit is contained in:
Unchained
2026-03-31 13:34:37 +02:00
parent 1c5ec1a271
commit 2b9d8fa7d5
3 changed files with 46 additions and 5 deletions

View File

@@ -1,5 +0,0 @@
import { createRouteHandler } from "@openpanel/nextjs/server";
export const { GET, POST } = createRouteHandler({
apiUrl: process.env.OPENPANEL_API_URL || "https://op.nodecrew.me/api",
});

View File

@@ -0,0 +1,22 @@
import { NextResponse } from "next/server";
const OPENPANEL_API_URL = "https://op.nodecrew.me/api";
export async function POST(request: Request) {
try {
const body = await request.json();
const response = await fetch(`${OPENPANEL_API_URL}/track`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body),
});
const data = await response.json();
return NextResponse.json(data, { status: response.status });
} catch (error) {
console.error("[OpenPanel] Track error:", error);
return NextResponse.json({ error: "Failed to track event" }, { status: 500 });
}
}

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 });
}
}