diff options
| author | nexxeln <[email protected]> | 2025-11-22 07:04:05 +0000 |
|---|---|---|
| committer | nexxeln <[email protected]> | 2025-11-22 07:04:05 +0000 |
| commit | 895f37ac899597dc66c40fb94f9e5bb43d60a42a (patch) | |
| tree | d0825db4ba52cdf5f404058135a8f88961f77a6a /apps/memory-graph-playground/src/app/api | |
| parent | package the graph (#563) (diff) | |
| download | supermemory-proxy-graph-requests.tar.xz supermemory-proxy-graph-requests.zip | |
runtime styles injection + let user proxy requests for data in graph package + new playground (#588)proxy-graph-requests
Diffstat (limited to 'apps/memory-graph-playground/src/app/api')
| -rw-r--r-- | apps/memory-graph-playground/src/app/api/graph/route.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/apps/memory-graph-playground/src/app/api/graph/route.ts b/apps/memory-graph-playground/src/app/api/graph/route.ts new file mode 100644 index 00000000..b7901966 --- /dev/null +++ b/apps/memory-graph-playground/src/app/api/graph/route.ts @@ -0,0 +1,46 @@ +import { NextResponse } from 'next/server' + +export async function POST(request: Request) { + try { + const body = await request.json() + const { apiKey, page = 1, limit = 500, sort = 'createdAt', order = 'desc' } = body + + if (!apiKey) { + return NextResponse.json( + { error: 'API key is required' }, + { status: 400 } + ) + } + + const response = await fetch('https://api.supermemory.ai/v3/documents/documents', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${apiKey}`, + }, + body: JSON.stringify({ + page, + limit, + sort, + order, + }), + }) + + if (!response.ok) { + const errorData = await response.json().catch(() => ({})) + return NextResponse.json( + { error: errorData.message || `API error: ${response.status}` }, + { status: response.status } + ) + } + + const data = await response.json() + return NextResponse.json(data) + } catch (error) { + console.error('Graph API error:', error) + return NextResponse.json( + { error: 'Failed to fetch documents' }, + { status: 500 } + ) + } +} |