add session-based connection management and React dashboard
Backend: adds JDBC session support, login/status/logout endpoints, and new DTOs (AuthResponse, ConnectionStatusResponse, LoginResult). Frontend replaces the Vite boilerplate with a Dashboard, ServiceCard, and ConnectModal backed by a typed API client. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
const BASE = import.meta.env.VITE_API_URL ?? '/api'
|
||||
|
||||
export async function apiFetch<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
const res = await fetch(`${BASE}${path}`, {
|
||||
...init,
|
||||
credentials: 'include',
|
||||
headers: { 'Content-Type': 'application/json', ...init?.headers },
|
||||
})
|
||||
if (!res.ok) {
|
||||
let message = `Request failed (${res.status})`
|
||||
try {
|
||||
const body = await res.json()
|
||||
if (body?.detail) message = body.detail
|
||||
else if (body?.title) message = body.title
|
||||
} catch {
|
||||
// ignore parse errors
|
||||
}
|
||||
throw new Error(message)
|
||||
}
|
||||
return res.status === 204 ? (undefined as T) : res.json()
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { apiFetch } from './client'
|
||||
import type { AuthResponse, ConnectionStatus, LoginRequest } from '../types/connection'
|
||||
|
||||
export const login = (req: LoginRequest) =>
|
||||
apiFetch<AuthResponse>('/login', { method: 'POST', body: JSON.stringify(req) })
|
||||
|
||||
export const getStatuses = () =>
|
||||
apiFetch<ConnectionStatus[]>('/connections/status')
|
||||
|
||||
export const logout = (serviceType: string) =>
|
||||
apiFetch<void>(`/connections/${serviceType}`, { method: 'DELETE' })
|
||||
Reference in New Issue
Block a user