MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / handleApiRoute

Function handleApiRoute

packages/sdks/nextjs/createNextRouteHandler.ts:45–73  ·  view source on GitHub ↗
(
  req: Request,
  apiUrl: string,
  apiPath: string,
)

Source from the content-addressed store, hash-verified

43}
44
45async function handleApiRoute(
46 req: Request,
47 apiUrl: string,
48 apiPath: string,
49): Promise<NextResponse> {
50 const headers = getClientHeaders(req);
51
52 try {
53 const res = await fetch(`${apiUrl}${apiPath}`, {
54 method: req.method,
55 headers,
56 body:
57 req.method === 'POST' ? JSON.stringify(await req.json()) : undefined,
58 });
59
60 if (res.headers.get('content-type')?.includes('application/json')) {
61 return NextResponse.json(await res.json(), { status: res.status });
62 }
63 return NextResponse.json(await res.text(), { status: res.status });
64 } catch (e) {
65 return NextResponse.json(
66 {
67 error: 'Failed to proxy request',
68 message: e instanceof Error ? e.message : String(e),
69 },
70 { status: 500 },
71 );
72 }
73}
74
75async function handleScriptProxyRoute(req: Request): Promise<NextResponse> {
76 const url = new URL(req.url);

Callers 1

handlerFunction · 0.70

Calls 4

getClientHeadersFunction · 0.70
fetchFunction · 0.50
stringifyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected