74 lines
2.6 KiB
HTML
74 lines
2.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Test Frontend-Backend Connection</title>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; margin: 40px; }
|
|
button { padding: 10px 20px; margin: 10px; cursor: pointer; }
|
|
#log { border: 1px solid #ccc; padding: 10px; margin-top: 20px; white-space: pre-wrap; }
|
|
.error { color: red; }
|
|
.success { color: green; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>Test Frontend-Backend Connection</h1>
|
|
<p>Click the button below to test the chat API</p>
|
|
<button onclick="testChat()">Test Chat API</button>
|
|
<button onclick="clearLog()">Clear Log</button>
|
|
<div id="log"></div>
|
|
|
|
<script>
|
|
const log = document.getElementById('log');
|
|
|
|
function logMessage(message, type = 'info') {
|
|
const div = document.createElement('div');
|
|
div.className = type;
|
|
div.textContent = new Date().toLocaleTimeString() + ': ' + message;
|
|
log.appendChild(div);
|
|
}
|
|
|
|
function clearLog() {
|
|
log.innerHTML = '';
|
|
}
|
|
|
|
async function testChat() {
|
|
logMessage('Testing chat API...', 'success');
|
|
logMessage('Sending POST to http://localhost:8000/api/chat');
|
|
logMessage('Request body: {"user_id": "default-user", "message": "hola"}');
|
|
|
|
try {
|
|
const response = await fetch('http://localhost:8000/api/chat', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
user_id: 'default-user',
|
|
message: 'hola',
|
|
}),
|
|
});
|
|
|
|
logMessage('Response status: ' + response.status + ' ' + response.statusText);
|
|
logMessage('Response OK: ' + response.ok);
|
|
|
|
if (!response.ok) {
|
|
logMessage('Error: Response not OK', 'error');
|
|
return;
|
|
}
|
|
|
|
const data = await response.json();
|
|
logMessage('Response received:', 'success');
|
|
logMessage('Response: ' + JSON.stringify(data, null, 2));
|
|
logMessage('AI Response: ' + data.response.substring(0, 100) + '...', 'success');
|
|
|
|
} catch (error) {
|
|
logMessage('ERROR: ' + error.message, 'error');
|
|
logMessage('Stack: ' + error.stack, 'error');
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|