feat: Add Wild Central web app (Central-only UI)
Extract Central pages from the wild-cloud web app into a standalone React app for Wild Central. Includes: - Central overview, DNS, DHCP, Firewall, VPN, Ingress, CrowdSec pages - Simplified sidebar with Central-only navigation - Branding updated to "Wild Central" - All Cloud-specific pages, components, hooks, and API services removed - TypeScript type-check and production build pass Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
132
web/src/services/api-legacy.ts
Normal file
132
web/src/services/api-legacy.ts
Normal file
@@ -0,0 +1,132 @@
|
||||
import type {
|
||||
Status,
|
||||
GlobalConfig,
|
||||
GlobalConfigResponse,
|
||||
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();
|
||||
}
|
||||
|
||||
private async requestText(endpoint: string, options?: RequestInit): Promise<string> {
|
||||
const url = `${this.baseUrl}${endpoint}`;
|
||||
const response = await fetch(url, options);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
return response.text();
|
||||
}
|
||||
|
||||
async getStatus(): Promise<Status> {
|
||||
return this.request<Status>('/api/status');
|
||||
}
|
||||
|
||||
async getHealth(): Promise<HealthResponse> {
|
||||
return this.request<HealthResponse>('/api/v1/health');
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Global Config APIs (Wild Central level)
|
||||
// Endpoint: /api/v1/config
|
||||
// ========================================
|
||||
|
||||
async getConfig(): Promise<GlobalConfigResponse> {
|
||||
return this.request<GlobalConfigResponse>('/api/v1/config');
|
||||
}
|
||||
|
||||
async getConfigYaml(): Promise<string> {
|
||||
return this.requestText('/api/v1/config/yaml');
|
||||
}
|
||||
|
||||
async updateConfigYaml(yamlContent: string): Promise<StatusResponse> {
|
||||
return this.request<StatusResponse>('/api/v1/config/yaml', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'text/plain' },
|
||||
body: yamlContent
|
||||
});
|
||||
}
|
||||
|
||||
async createConfig(config: GlobalConfig): Promise<StatusResponse> {
|
||||
return this.request<StatusResponse>('/api/v1/config', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(config)
|
||||
});
|
||||
}
|
||||
|
||||
async updateConfig(config: GlobalConfig): Promise<StatusResponse> {
|
||||
return this.request<StatusResponse>('/api/v1/config', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(config)
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
Reference in New Issue
Block a user