90 lines
3.4 KiB
HTML
90 lines
3.4 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Test Direct API</title>
|
|
<style>
|
|
body { font-family: monospace; padding: 20px; background: #1a1a1a; color: #0f0; }
|
|
button { padding: 10px 20px; margin: 10px; font-size: 16px; }
|
|
pre { background: #000; padding: 15px; border: 1px solid #0f0; overflow: auto; }
|
|
.success { color: #0f0; }
|
|
.error { color: #f00; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>🧪 Test Direct de l'API</h1>
|
|
|
|
<button onclick="testAPI()">Tester l'API avec Token Direct</button>
|
|
<button onclick="checkToken()">Vérifier Token LocalStorage</button>
|
|
<button onclick="installToken()">Installer Token</button>
|
|
|
|
<h2>Résultats :</h2>
|
|
<div id="results"></div>
|
|
|
|
<script>
|
|
const TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1YTIzOThkZi00NWNiLTQyOGQtOWY1ZS04YzQwNzQxNzEyNGIiLCJpYXQiOjE3NjMwODM0NjksImV4cCI6MTc2MzY4ODI2OX0.fCxlIzy-RkCqvCwjatHmIZ5pjqC61Vs-RAnZwulNd_Q';
|
|
|
|
function log(message, isError = false) {
|
|
const div = document.getElementById('results');
|
|
const pre = document.createElement('pre');
|
|
pre.className = isError ? 'error' : 'success';
|
|
pre.textContent = message;
|
|
div.appendChild(pre);
|
|
}
|
|
|
|
function installToken() {
|
|
localStorage.clear();
|
|
localStorage.setItem('auth_token', TOKEN);
|
|
localStorage.setItem('token', TOKEN);
|
|
log('✅ Token installé avec les clés: auth_token et token');
|
|
log('Token: ' + TOKEN.substring(0, 50) + '...');
|
|
}
|
|
|
|
function checkToken() {
|
|
const authToken = localStorage.getItem('auth_token');
|
|
const token = localStorage.getItem('token');
|
|
|
|
log('🔍 Vérification LocalStorage:');
|
|
log('auth_token: ' + (authToken ? authToken.substring(0, 50) + '...' : 'NON TROUVÉ'), !authToken);
|
|
log('token: ' + (token ? token.substring(0, 50) + '...' : 'NON TROUVÉ'), !token);
|
|
}
|
|
|
|
async function testAPI() {
|
|
log('🚀 Test de l\'API...');
|
|
log('URL: http://localhost:4000/api/draw/eligible-participants');
|
|
log('Token utilisé: ' + TOKEN.substring(0, 50) + '...');
|
|
|
|
try {
|
|
const response = await fetch('http://localhost:4000/api/draw/eligible-participants?minTickets=1&verified=true', {
|
|
method: 'GET',
|
|
headers: {
|
|
'Authorization': 'Bearer ' + TOKEN,
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
log('📥 Réponse: ' + response.status + ' ' + response.statusText, !response.ok);
|
|
|
|
const data = await response.json();
|
|
|
|
if (response.ok) {
|
|
log('✅ SUCCÈS!');
|
|
log('Participants: ' + data.data.total);
|
|
log(JSON.stringify(data, null, 2));
|
|
} else {
|
|
log('❌ ERREUR:', true);
|
|
log(JSON.stringify(data, null, 2), true);
|
|
}
|
|
} catch (error) {
|
|
log('💥 ERREUR RÉSEAU: ' + error.message, true);
|
|
log('Le serveur backend n\'est peut-être pas actif sur le port 4000', true);
|
|
}
|
|
}
|
|
|
|
// Auto-check au chargement
|
|
window.onload = () => {
|
|
checkToken();
|
|
};
|
|
</script>
|
|
</body>
|
|
</html>
|