Files
dashcaddy/status/api/test-api.js
Sami f61e85d9a7 Initial commit: DashCaddy v1.0
Full codebase including API server (32 modules + routes), dashboard frontend,
DashCA certificate distribution, installer script, and deployment skills.
2026-03-05 02:26:12 -08:00

73 lines
2.4 KiB
JavaScript

// Simple test script to verify API connectivity
const http = require('http');
const API_URL = 'http://localhost:3001';
function makeRequest(path) {
return new Promise((resolve, reject) => {
http.get(`${API_URL}${path}`, (res) => {
let data = '';
res.on('data', (chunk) => data += chunk);
res.on('end', () => {
try {
resolve({ status: res.statusCode, data: JSON.parse(data) });
} catch (e) {
resolve({ status: res.statusCode, data: data });
}
});
}).on('error', reject);
});
}
async function runTests() {
console.log('Testing SAMI-CLOUD API...\n');
// Test 1: Health Check
console.log('1. Testing health endpoint...');
try {
const health = await makeRequest('/health');
if (health.status === 200) {
console.log(' ✓ Health check passed');
} else {
console.log(' ✗ Health check failed:', health.status);
}
} catch (error) {
console.log(' ✗ Health check error:', error.message);
}
// Test 2: API Test Endpoint
console.log('\n2. Testing API test endpoint...');
try {
const test = await makeRequest('/api/caddy/test');
if (test.status === 200) {
console.log(' ✓ API test passed');
console.log(' Platform:', test.data.platform);
console.log(' Caddy Admin API:', test.data.caddyAdminApi);
console.log(' DNS Server API:', test.data.dnsServerApi);
console.log(' DNS Token:', test.data.dnsTokenConfigured ? 'Configured' : 'Not configured');
} else {
console.log(' ✗ API test failed:', test.status);
}
} catch (error) {
console.log(' ✗ API test error:', error.message);
}
// Test 3: Services Endpoint
console.log('\n3. Testing services endpoint...');
try {
const services = await makeRequest('/api/services');
if (services.status === 200) {
console.log(' ✓ Services endpoint passed');
console.log(' Found', services.data.services.length, 'services');
} else {
console.log(' ✗ Services endpoint failed:', services.status);
}
} catch (error) {
console.log(' ✗ Services endpoint error:', error.message);
}
console.log('\nTests complete!');
}
runTests().catch(console.error);