Initial commit - PromptTech
This commit is contained in:
148
tests/test_api.html
Normal file
148
tests/test_api.html
Normal file
@@ -0,0 +1,148 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Services API Direct Test</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 1200px;
|
||||
margin: 50px auto;
|
||||
padding: 20px;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
.container {
|
||||
background: white;
|
||||
padding: 30px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
h1 {
|
||||
color: #333;
|
||||
}
|
||||
.status {
|
||||
padding: 15px;
|
||||
margin: 15px 0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.success {
|
||||
background: #d4edda;
|
||||
border: 1px solid #c3e6cb;
|
||||
color: #155724;
|
||||
}
|
||||
.error {
|
||||
background: #f8d7da;
|
||||
border: 1px solid #f5c6cb;
|
||||
color: #721c24;
|
||||
}
|
||||
.service-card {
|
||||
border: 1px solid #ddd;
|
||||
padding: 15px;
|
||||
margin: 10px 0;
|
||||
border-radius: 4px;
|
||||
background: #fafafa;
|
||||
}
|
||||
button {
|
||||
background: #007bff;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
}
|
||||
button:hover {
|
||||
background: #0056b3;
|
||||
}
|
||||
pre {
|
||||
background: #f4f4f4;
|
||||
padding: 10px;
|
||||
border-radius: 4px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>🔧 Services API Direct Test</h1>
|
||||
<p>This page directly tests if the backend services API is working.</p>
|
||||
|
||||
<button onclick="testAPI()">Test API Now</button>
|
||||
<button onclick="location.href='http://localhost:5300/services'">
|
||||
Go to Services Page
|
||||
</button>
|
||||
|
||||
<div id="result"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
async function testAPI() {
|
||||
const resultDiv = document.getElementById("result");
|
||||
resultDiv.innerHTML = '<div class="status">Testing API...</div>';
|
||||
|
||||
try {
|
||||
// Test 1: Backend Health
|
||||
const healthResponse = await fetch(
|
||||
"http://localhost:8181/api/health"
|
||||
);
|
||||
const healthData = await healthResponse.json();
|
||||
|
||||
// Test 2: Services API
|
||||
const servicesResponse = await fetch(
|
||||
"http://localhost:8181/api/services"
|
||||
);
|
||||
const servicesData = await servicesResponse.json();
|
||||
|
||||
// Display results
|
||||
let html = `
|
||||
<div class="status success">
|
||||
<strong>✅ Backend API Working!</strong><br>
|
||||
Health: ${healthData.status}<br>
|
||||
Database: ${healthData.database}<br>
|
||||
Services Found: ${servicesData.length}
|
||||
</div>
|
||||
|
||||
<h3>Services Data:</h3>
|
||||
`;
|
||||
|
||||
servicesData.forEach((service) => {
|
||||
html += `
|
||||
<div class="service-card">
|
||||
<strong>${service.name}</strong> - $${
|
||||
service.price
|
||||
}<br>
|
||||
<small>Category: ${service.category} | Duration: ${
|
||||
service.duration
|
||||
}</small><br>
|
||||
<small style="color: #666;">${service.description.substring(
|
||||
0,
|
||||
100
|
||||
)}</small>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
|
||||
html += `
|
||||
<h3>Raw Response:</h3>
|
||||
<pre>${JSON.stringify(servicesData[0], null, 2)}</pre>
|
||||
`;
|
||||
|
||||
resultDiv.innerHTML = html;
|
||||
} catch (error) {
|
||||
resultDiv.innerHTML = `
|
||||
<div class="status error">
|
||||
<strong>❌ Error:</strong><br>
|
||||
${error.message}<br><br>
|
||||
<strong>Possible causes:</strong><br>
|
||||
- Backend not running on port 8181<br>
|
||||
- CORS not configured<br>
|
||||
- Network connectivity issue
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-test on load
|
||||
window.onload = () => testAPI();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user