forked from gabriela-sotero/mentorIA-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api.html
More file actions
48 lines (43 loc) · 1.81 KB
/
Copy pathtest-api.html
File metadata and controls
48 lines (43 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Teste API</title>
</head>
<body>
<h1>Teste de Comunicação com Backend</h1>
<button onclick="testAPI()">Testar API</button>
<div id="result"></div>
<script>
async function testAPI() {
const resultDiv = document.getElementById('result');
resultDiv.innerHTML = 'Testando...';
try {
console.log('🌐 Testando comunicação com backend...');
const response = await fetch('http://localhost:3000/api/questions/session?maxQuestions=5', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer test-token'
}
});
console.log('📊 Status:', response.status);
console.log('📋 Headers:', response.headers);
if (response.ok) {
const data = await response.json();
console.log('✅ Dados recebidos:', data);
resultDiv.innerHTML = `<pre>✅ Sucesso! Dados: ${JSON.stringify(data, null, 2)}</pre>`;
} else {
const errorText = await response.text();
console.error('❌ Erro:', errorText);
resultDiv.innerHTML = `<pre>❌ Erro ${response.status}: ${errorText}</pre>`;
}
} catch (error) {
console.error('❌ Erro de rede:', error);
resultDiv.innerHTML = `<pre>❌ Erro de rede: ${error.message}</pre>`;
}
}
</script>
</body>
</html>