feat: api health check and version display
This commit is contained in:
@@ -8,14 +8,23 @@ import {
|
||||
} from '@/lib/schemas/config';
|
||||
import * as z from 'zod';
|
||||
|
||||
export type ConfigAuditRecord = {
|
||||
id: string;
|
||||
serverId: string;
|
||||
configFile: string;
|
||||
oldConfig: string;
|
||||
newConfig: string;
|
||||
changedAt: string;
|
||||
};
|
||||
|
||||
const serverRoute = '/server';
|
||||
|
||||
export async function getServerConfigurations(
|
||||
token: string,
|
||||
serverId: string
|
||||
): Promise<Configurations> {
|
||||
const response = await fetchServerAPI<Configurations>(`${serverRoute}/${serverId}/config`, token);
|
||||
return configurationsSchema.parse(response.data);
|
||||
const response = await fetchServerAPI<Configurations>(`${serverRoute}/${serverId}/config`, token);
|
||||
return configurationsSchema.parse(response.data);
|
||||
}
|
||||
|
||||
export function validateConfig(
|
||||
@@ -45,8 +54,26 @@ export async function updateServerConfiguration(
|
||||
config: Config,
|
||||
restart = false
|
||||
): Promise<void> {
|
||||
await fetchServerAPI(`${serverRoute}/${serverId}/config/${configType}?override=true`, token, 'PUT', {
|
||||
...validateConfig(configType, config),
|
||||
restart
|
||||
});
|
||||
await fetchServerAPI(
|
||||
`${serverRoute}/${serverId}/config/${configType}?override=true&restart=${restart}`,
|
||||
token,
|
||||
'PUT',
|
||||
{
|
||||
...validateConfig(configType, config)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function bulkUpdateServerConfigurations(
|
||||
token: string,
|
||||
serverId: string,
|
||||
configs: Configurations,
|
||||
restart = false
|
||||
): Promise<void> {
|
||||
await fetchServerAPI<ConfigAuditRecord[]>(
|
||||
`${serverRoute}/${serverId}/config?override=true&restart=${restart}`,
|
||||
token,
|
||||
'PATCH',
|
||||
configs
|
||||
);
|
||||
}
|
||||
|
||||
17
src/lib/api/server/health.ts
Normal file
17
src/lib/api/server/health.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
const BASE_URL = process.env.API_BASE_URL || 'http://localhost:8080';
|
||||
|
||||
export type HealthStatus = { healthy: true; version: string } | { healthy: false; version: null };
|
||||
|
||||
export async function checkHealth(): Promise<HealthStatus> {
|
||||
try {
|
||||
const response = await fetch(`${BASE_URL}/system/health`, {
|
||||
method: 'GET',
|
||||
next: { revalidate: 0 }
|
||||
});
|
||||
if (!response.ok) return { healthy: false, version: null };
|
||||
const version = await response.text();
|
||||
return { healthy: true, version: version.trim() || 'unknown' };
|
||||
} catch {
|
||||
return { healthy: false, version: null };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user