Files
johndoe6345789 e51c7be9ba feat(dbal): add login gate + CLI mode to Query Console
- 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>
2026-03-18 22:33:57 +00:00

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 })
}
}