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, + }); + } +} diff --git a/src/app/api/op1/route.ts b/src/app/api/op1/route.ts new file mode 100644 index 0000000..5b5259c --- /dev/null +++ b/src/app/api/op1/route.ts @@ -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 }); + } +}