| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>API Test</title> |
| <style> |
| body { font-family: Arial; padding: 20px; background: #1a1a1a; color: #fff; } |
| button { padding: 10px 20px; margin: 10px; background: #c8f04e; border: none; cursor: pointer; font-size: 16px; } |
| pre { background: #2a2a2a; padding: 15px; border-radius: 8px; overflow-x: auto; } |
| .success { color: #4ade80; } |
| .error { color: #ff4d4d; } |
| </style> |
| </head> |
| <body> |
| <h1>🧪 Moharek API Test</h1> |
| |
| <button onclick="testAPI()">Test API Connection</button> |
| <button onclick="testLogin()">Test Login</button> |
| |
| <h3>Results:</h3> |
| <pre id="results"></pre> |
|
|
| <script> |
| const API = window.location.origin + '/api'; |
| |
| document.getElementById('results').textContent = |
| 'Origin: ' + window.location.origin + '\n' + |
| 'API URL: ' + API + '\n' + |
| 'Timestamp: ' + new Date().toISOString(); |
| |
| async function testAPI() { |
| const results = document.getElementById('results'); |
| results.textContent += '\n\n--- Testing API ---\n'; |
| |
| try { |
| const res = await fetch(API + '/health'); |
| results.textContent += 'Health Status: ' + res.status + '\n'; |
| const data = await res.json(); |
| results.textContent += 'Health Data: ' + JSON.stringify(data, null, 2) + '\n'; |
| } catch (err) { |
| results.textContent += 'ERROR: ' + err.message + '\n'; |
| } |
| } |
| |
| async function testLogin() { |
| const results = document.getElementById('results'); |
| results.textContent += '\n\n--- Testing Login ---\n'; |
| |
| try { |
| const res = await fetch(API + '/users/login', { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify({ |
| email: 'admin@moharek.com', |
| password: 'admin123' |
| }) |
| }); |
| results.textContent += 'Login Status: ' + res.status + '\n'; |
| const data = await res.json(); |
| results.textContent += 'Login Data: ' + JSON.stringify(data, null, 2) + '\n'; |
| } catch (err) { |
| results.textContent += 'ERROR: ' + err.message + '\n'; |
| } |
| } |
| |
| |
| setTimeout(testAPI, 500); |
| </script> |
| </body> |
| </html> |
|
|