// API connection test script document.addEventListener('DOMContentLoaded', function() { // Element to display test results const resultElement = document.getElementById('apiTestResult'); if (resultElement) { resultElement.innerHTML = '

Checking API connection...

'; // Check for authentication token const token = localStorage.getItem('auth_token'); const options = { method: 'GET', headers: { 'Content-Type': 'application/json' } }; // Add auth token if available if (token) { options.headers['Authorization'] = `Bearer ${token}`; } // Test API connection fetch('/api/warranties', options) .then(response => { if (!response.ok) { throw new Error('API responded with status: ' + response.status); } return response.json(); }) .then(data => { console.log('API response:', data); resultElement.innerHTML = `

✅ API Connection Successful

The API responded with ${data && Array.isArray(data) ? data.length : 0} warranties.

${JSON.stringify(data && data.length ? data[0] : {}, null, 2)}
`; }) .catch(error => { console.error('API connection error:', error); resultElement.innerHTML = `

❌ API Connection Failed

Error: ${error.message}

Debug Information:
`; }); } });