mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Add debugging tools to test production endpoints and diagnose issues
Add a new Node.js script (`debug_production.js`) to test various API endpoints in the production environment, including health checks, credential validation, login attempts, and task-related operations. Also includes an HTML file (`test_task_update.html`) for manually testing the task update endpoint. Replit-Commit-Author: Agent Replit-Commit-Session-Id: cc2d271b-82f0-4d6a-9302-a0b067ffb429 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/cc2d271b-82f0-4d6a-9302-a0b067ffb429/grlWN1D
This commit is contained in:
1 parent
54c637b7b6
commit
c3f08bb788
3 files changed
+260
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 315 KiB |
@@ -0,0 +1,136 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// Script de débogage pour tester les endpoints de production
|
||||
import https from 'https';
|
||||
|
||||
const BASE_URL = 'https://logiflow.ffnancy.fr';
|
||||
|
||||
async function makeRequest(path, options = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const url = new URL(path, BASE_URL);
|
||||
const requestOptions = {
|
||||
hostname: url.hostname,
|
||||
path: url.pathname + url.search,
|
||||
method: options.method || 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'User-Agent': 'Debug-Script/1.0',
|
||||
...options.headers
|
||||
}
|
||||
};
|
||||
|
||||
const req = https.request(requestOptions, (res) => {
|
||||
let data = '';
|
||||
res.on('data', (chunk) => data += chunk);
|
||||
res.on('end', () => {
|
||||
resolve({
|
||||
status: res.statusCode,
|
||||
headers: res.headers,
|
||||
data: data,
|
||||
length: data.length
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (error) => {
|
||||
reject(error);
|
||||
});
|
||||
|
||||
if (options.body) {
|
||||
req.write(options.body);
|
||||
}
|
||||
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
async function debugProduction() {
|
||||
console.log('🔍 Testing production endpoints...\n');
|
||||
|
||||
try {
|
||||
// Test 1: Health check
|
||||
console.log('1. Health check:');
|
||||
const health = await makeRequest('/api/health');
|
||||
console.log(` Status: ${health.status}`);
|
||||
console.log(` Response: ${health.data.substring(0, 100)}...\n`);
|
||||
|
||||
// Test 2: Default credentials check
|
||||
console.log('2. Default credentials check:');
|
||||
const defaultCreds = await makeRequest('/api/default-credentials-check');
|
||||
console.log(` Status: ${defaultCreds.status}`);
|
||||
console.log(` Response: ${defaultCreds.data}\n`);
|
||||
|
||||
// Test 3: Login attempts with different credentials
|
||||
const credentialsList = [
|
||||
{ username: 'admin', password: 'admin' },
|
||||
{ username: 'administrator', password: 'administrator' },
|
||||
{ username: 'lff', password: 'lff2024' },
|
||||
{ username: 'logiflow', password: 'logiflow' },
|
||||
{ username: 'root', password: 'root' }
|
||||
];
|
||||
|
||||
let login = null;
|
||||
let cookies = '';
|
||||
|
||||
for (const creds of credentialsList) {
|
||||
console.log(`3. Login attempt with ${creds.username}:${creds.password}:`);
|
||||
login = await makeRequest('/api/login', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(creds)
|
||||
});
|
||||
console.log(` Status: ${login.status}`);
|
||||
console.log(` Response: ${login.data.substring(0, 200)}...\n`);
|
||||
|
||||
if (login.status === 200 && login.headers['set-cookie']) {
|
||||
cookies = login.headers['set-cookie'].map(c => c.split(';')[0]).join('; ');
|
||||
console.log(`✅ Successful login with ${creds.username}\n`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Cookies already extracted above if login was successful
|
||||
|
||||
// Test 4: User info (with cookies)
|
||||
if (cookies) {
|
||||
console.log('4. User info (authenticated):');
|
||||
const user = await makeRequest('/api/user', {
|
||||
headers: { 'Cookie': cookies }
|
||||
});
|
||||
console.log(` Status: ${user.status}`);
|
||||
console.log(` Response: ${user.data.substring(0, 200)}...\n`);
|
||||
|
||||
// Test 5: Tasks (with cookies)
|
||||
console.log('5. Tasks list (authenticated):');
|
||||
const tasks = await makeRequest('/api/tasks', {
|
||||
headers: { 'Cookie': cookies }
|
||||
});
|
||||
console.log(` Status: ${tasks.status}`);
|
||||
console.log(` Response: ${tasks.data.substring(0, 300)}...\n`);
|
||||
|
||||
// Test 6: Test task update (with cookies) - testing the problematic endpoint
|
||||
console.log('6. Task update test (problematic endpoint):');
|
||||
const taskUpdate = await makeRequest('/api/tasks/99', {
|
||||
method: 'PUT',
|
||||
headers: { 'Cookie': cookies },
|
||||
body: JSON.stringify({
|
||||
title: 'Test Debug',
|
||||
description: 'Test de debug',
|
||||
priority: 'medium',
|
||||
status: 'pending',
|
||||
assignedTo: 'admin',
|
||||
startDate: '2025-08-20',
|
||||
dueDate: null
|
||||
})
|
||||
});
|
||||
console.log(` Status: ${taskUpdate.status}`);
|
||||
console.log(` Response: ${taskUpdate.data}\n`);
|
||||
} else {
|
||||
console.log('❌ No cookies received from login - cannot test authenticated endpoints\n');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Error during debug:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
debugProduction();
|
||||
@@ -0,0 +1,124 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test Task Update - Production Debug</title>
|
||||
<style>
|
||||
body { font-family: monospace; padding: 20px; }
|
||||
.log { margin: 10px 0; padding: 10px; background: #f5f5f5; }
|
||||
.error { background: #ffe6e6; }
|
||||
.success { background: #e6ffe6; }
|
||||
button { padding: 10px; margin: 5px; }
|
||||
textarea, input { width: 100%; margin: 5px 0; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Test Task Update - Production Debug</h1>
|
||||
|
||||
<div>
|
||||
<h3>1. D'abord, connectez-vous manuellement sur LogiFlow</h3>
|
||||
<p>Ouvrez <a href="https://logiflow.ffnancy.fr" target="_blank">LogiFlow</a> dans un autre onglet et connectez-vous avec vos vrais identifiants.</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h3>2. Test de l'endpoint problématique</h3>
|
||||
<label>Task ID à tester:</label>
|
||||
<input type="number" id="taskId" value="99" />
|
||||
|
||||
<label>JSON des données à envoyer:</label>
|
||||
<textarea id="taskData" rows="10">{
|
||||
"title": "Test Debug",
|
||||
"description": "Test de debug depuis le script",
|
||||
"priority": "medium",
|
||||
"status": "pending",
|
||||
"assignedTo": "admin",
|
||||
"startDate": "2025-08-20",
|
||||
"dueDate": null
|
||||
}</textarea>
|
||||
|
||||
<button onclick="testTaskUpdate()">Test Task Update (PUT)</button>
|
||||
<button onclick="clearLogs()">Clear Logs</button>
|
||||
</div>
|
||||
|
||||
<div id="logs"></div>
|
||||
|
||||
<script>
|
||||
function log(message, type = 'info') {
|
||||
const logs = document.getElementById('logs');
|
||||
const div = document.createElement('div');
|
||||
div.className = `log ${type}`;
|
||||
div.innerHTML = `[${new Date().toLocaleTimeString()}] ${message}`;
|
||||
logs.insertBefore(div, logs.firstChild);
|
||||
}
|
||||
|
||||
function clearLogs() {
|
||||
document.getElementById('logs').innerHTML = '';
|
||||
}
|
||||
|
||||
async function testTaskUpdate() {
|
||||
const taskId = document.getElementById('taskId').value;
|
||||
const taskData = document.getElementById('taskData').value;
|
||||
|
||||
log(`Testing task update for ID: ${taskId}`);
|
||||
|
||||
try {
|
||||
// Parse JSON data
|
||||
const data = JSON.parse(taskData);
|
||||
log(`Parsed data: ${JSON.stringify(data, null, 2)}`);
|
||||
|
||||
// Test the problematic endpoint
|
||||
const response = await fetch(`/api/tasks/${taskId}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
credentials: 'same-origin', // Important pour envoyer les cookies de session
|
||||
body: taskData
|
||||
});
|
||||
|
||||
log(`Response status: ${response.status} ${response.statusText}`);
|
||||
|
||||
if (response.ok) {
|
||||
const result = await response.json();
|
||||
log(`Success! Response: ${JSON.stringify(result, null, 2)}`, 'success');
|
||||
} else {
|
||||
const error = await response.text();
|
||||
log(`Error response: ${error}`, 'error');
|
||||
|
||||
// Additional debug info
|
||||
log(`Response headers: ${JSON.stringify([...response.headers.entries()])}`, 'error');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
log(`JavaScript error: ${error.message}`, 'error');
|
||||
log(`Stack trace: ${error.stack}`, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Test connectivity on load
|
||||
window.onload = function() {
|
||||
log('Script loaded. Please login to LogiFlow first!');
|
||||
|
||||
// Test if we can reach the API
|
||||
fetch('/api/user')
|
||||
.then(response => {
|
||||
if (response.status === 401) {
|
||||
log('Not authenticated - please login first', 'error');
|
||||
} else if (response.ok) {
|
||||
log('Authenticated successfully', 'success');
|
||||
return response.json();
|
||||
} else {
|
||||
log(`Unexpected status: ${response.status}`, 'error');
|
||||
}
|
||||
})
|
||||
.then(user => {
|
||||
if (user) {
|
||||
log(`Logged in as: ${user.username} (${user.role})`, 'success');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
log(`Connection test failed: ${error.message}`, 'error');
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user