Initial commit: website
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
const MESHKEE_API_URL =
|
||||
process.env.MESHKEE_API_URL?.replace(/\/$/, "") ||
|
||||
process.env.NEXT_PUBLIC_MESHKEE_API_URL?.replace(/\/$/, "") ||
|
||||
"https://api.meshkee.com/api/v1";
|
||||
|
||||
function authHeader(request: NextRequest): string | null {
|
||||
const incoming = request.headers.get("authorization")?.trim();
|
||||
if (incoming) return incoming;
|
||||
|
||||
const token = process.env.MESHKEE_API_TOKEN?.trim();
|
||||
return token ? `Bearer ${token}` : null;
|
||||
}
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const auth = authHeader(request);
|
||||
if (!auth) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
message:
|
||||
"Meshkee categories need auth. Set MESHKEE_API_TOKEN or sign in on the dashboard first.",
|
||||
},
|
||||
{ status: 503 },
|
||||
);
|
||||
}
|
||||
|
||||
const q = request.nextUrl.searchParams.get("q")?.trim() ?? "";
|
||||
const params = new URLSearchParams();
|
||||
if (q) params.set("q", q);
|
||||
|
||||
const response = await fetch(
|
||||
`${MESHKEE_API_URL}/business-categories?${params}`,
|
||||
{
|
||||
headers: { Authorization: auth },
|
||||
cache: "no-store",
|
||||
},
|
||||
);
|
||||
|
||||
const payload = await response.json().catch(() => null);
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
payload ?? { message: `Meshkee error (${response.status})` },
|
||||
{ status: response.status },
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json(payload);
|
||||
}
|
||||
Reference in New Issue
Block a user