Files
wild-central/web/src/services/api-legacy.ts
Paul Payne 79f38d2750 Replace state blob with resource-oriented API endpoints
Split /api/v1/state into dedicated resource endpoints:
- /api/v1/operator, /api/v1/central-domain
- /api/v1/ddns/config, /api/v1/dns/settings
- /api/v1/dhcp/config (moved from /dnsmasq/dhcp/)
- /api/v1/nftables/config, /api/v1/haproxy/routes

Each page now talks to its own resource instead of deep-merging
a blob. Removes useConfig hook, CentralState type, and legacy
config methods.
2026-07-10 22:45:36 +00:00

83 lines
2.1 KiB
TypeScript

import type {
Status,
HealthResponse,
StatusResponse,
NetworkInfo,
DnsmasqStatus,
DnsmasqConfigResponse
} from '../types';
import { getApiBaseUrl } from './api/config';
const API_BASE = getApiBaseUrl();
class ApiService {
private baseUrl: string;
constructor(baseUrl: string = API_BASE) {
this.baseUrl = baseUrl;
}
private async request<T>(endpoint: string, options?: RequestInit): Promise<T> {
const url = `${this.baseUrl}${endpoint}`;
const response = await fetch(url, options);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
}
async getStatus(): Promise<Status> {
return this.request<Status>('/api/status');
}
async getHealth(): Promise<HealthResponse> {
return this.request<HealthResponse>('/api/v1/health');
}
async getDnsmasqStatus(): Promise<DnsmasqStatus> {
return this.request<DnsmasqStatus>('/api/v1/dnsmasq/status');
}
async getDnsmasqConfig(): Promise<DnsmasqConfigResponse> {
return this.request<DnsmasqConfigResponse>('/api/v1/dnsmasq/config');
}
async writeDnsmasqConfig(content: string): Promise<StatusResponse> {
return this.request<StatusResponse>('/api/v1/dnsmasq/config', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ content }),
});
}
async generateDnsmasqConfig(overwrite: boolean = false): Promise<DnsmasqConfigResponse> {
const url = overwrite ? '/api/v1/dnsmasq/generate?overwrite=true' : '/api/v1/dnsmasq/generate';
return this.request<DnsmasqConfigResponse>(url, {
method: 'POST'
});
}
async restartDnsmasq(): Promise<StatusResponse> {
return this.request<StatusResponse>('/api/v1/dnsmasq/restart', {
method: 'POST'
});
}
async getNetworkInfo(): Promise<NetworkInfo> {
return this.request<NetworkInfo>('/api/v1/network/info');
}
async downloadPXEAssets(): Promise<StatusResponse> {
return this.request<StatusResponse>('/api/v1/assets', {
method: 'POST'
});
}
}
export const apiService = new ApiService();
export default ApiService;