mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-28 15:54:56 +00:00
- Login screen with admin token (default pre-configured for local dev) - CLI mode: type dbal commands directly (list, read, create, update, delete, rest, ping) - Clickable example commands for quick start - CLI/GUI mode toggle - Token persisted in localStorage, forwarded as Bearer auth - History shows CLI commands with $ prefix - Disconnect button to logout Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
const DBAL_DAEMON_URL = process.env.DBAL_DAEMON_URL ?? 'http://localhost:8080'
|
|
|
|
export async function POST(request: NextRequest) {
|
|
const { method, path, body, token } = await request.json()
|
|
|
|
const url = `${DBAL_DAEMON_URL}${path}`
|
|
|
|
try {
|
|
const headers: Record<string, string> = {
|
|
'Content-Type': 'application/json',
|
|
}
|
|
|
|
if (token) {
|
|
headers['Authorization'] = `Bearer ${token}`
|
|
}
|
|
|
|
const fetchOptions: RequestInit = {
|
|
method: method,
|
|
headers,
|
|
signal: AbortSignal.timeout(10000),
|
|
}
|
|
|
|
if (body && (method === 'POST' || method === 'PUT')) {
|
|
fetchOptions.body = JSON.stringify(body)
|
|
}
|
|
|
|
const response = await fetch(url, fetchOptions)
|
|
const text = await response.text()
|
|
let data: unknown
|
|
try {
|
|
data = JSON.parse(text)
|
|
} catch {
|
|
data = { raw: text }
|
|
}
|
|
|
|
return NextResponse.json({
|
|
status: response.status,
|
|
statusText: response.statusText,
|
|
data,
|
|
url,
|
|
timestamp: new Date().toISOString(),
|
|
})
|
|
} catch (err) {
|
|
return NextResponse.json({
|
|
status: 0,
|
|
statusText: 'Network Error',
|
|
data: { error: err instanceof Error ? err.message : 'Unknown error' },
|
|
url,
|
|
timestamp: new Date().toISOString(),
|
|
}, { status: 502 })
|
|
}
|
|
}
|