#!/usr/bin/env node
import fetch from 'node-fetch';
const BASE_URL = 'http://localhost:8080';
async function testHttpServer() {
console.log('Testing HTTP Server...\n');
try {
// Test health endpoint
console.log('1. Testing health endpoint...');
const healthResponse = await fetch(`${BASE_URL}/api/health`);
const healthData = await healthResponse.json();
console.log('✅ Health check:', healthData);
console.log('');
// Test root endpoint
console.log('2. Testing root endpoint...');
const rootResponse = await fetch(`${BASE_URL}/`);
const rootData = await rootResponse.json();
console.log('✅ Root endpoint:', rootData);
console.log('');
// Test diagrams list endpoint
console.log('3. Testing diagrams list endpoint...');
const diagramsResponse = await fetch(`${BASE_URL}/api/diagrams`);
const diagramsData = await diagramsResponse.json();
console.log('✅ Diagrams list:', diagramsData);
console.log('');
if (diagramsData.diagrams && diagramsData.diagrams.length > 0) {
const firstDiagram = diagramsData.diagrams[0];
console.log(`4. Testing diagram access for: ${firstDiagram.name}`);
// Test diagram view
const diagramResponse = await fetch(`${BASE_URL}${firstDiagram.url}`);
console.log(`✅ Diagram view status: ${diagramResponse.status}`);
// Test diagram download
const downloadResponse = await fetch(`${BASE_URL}${firstDiagram.downloadUrl}`);
console.log(`✅ Diagram download status: ${downloadResponse.status}`);
} else {
console.log('4. No diagrams found to test access');
}
} catch (error) {
console.error('❌ Error testing HTTP server:', error.message);
}
}
// Run the test
testHttpServer();