| <!DOCTYPE html> |
| <html lang="ar" dir="rtl"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <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; } |
| pre { background: #2a2a2a; padding: 15px; border-radius: 8px; overflow-x: auto; } |
| .success { color: #4ade80; } |
| .error { color: #ff4d4d; } |
| </style> |
| </head> |
| <body> |
| <h1>π§ͺ API Connection Test</h1> |
| |
| <div> |
| <h3>Current URL Info:</h3> |
| <pre id="urlInfo"></pre> |
| </div> |
|
|
| <button onclick="testHealth()">Test Health Endpoint</button> |
| <button onclick="testRegister()">Test Register</button> |
| <button onclick="testLogin()">Test Login</button> |
| |
| <div> |
| <h3>Results:</h3> |
| <pre id="results"></pre> |
| </div> |
|
|
| <script> |
| const API = window.location.origin + '/api'; |
| |
| document.getElementById('urlInfo').textContent = |
| 'Origin: ' + window.location.origin + '\n' + |
| 'API URL: ' + API + '\n' + |
| 'Full URL: ' + window.location.href; |
| |
| function log(msg, isError = false) { |
| const el = document.getElementById('results'); |
| const className = isError ? 'error' : 'success'; |
| el.innerHTML += `<div class="${className}">${new Date().toLocaleTimeString()}: ${msg}</div>`; |
| } |
| |
| async function testHealth() { |
| log('Testing /health endpoint...'); |
| try { |
| const res = await fetch(API.replace('/api', '/health')); |
| const data = await res.json(); |
| log('β
Health check: ' + JSON.stringify(data, null, 2)); |
| } catch (err) { |
| log('β Health check failed: ' + err.message, true); |
| } |
| } |
| |
| async function testRegister() { |
| log('Testing /api/users/register...'); |
| const testEmail = 'test' + Date.now() + '@test.com'; |
| try { |
| const res = await fetch(API + '/users/register', { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify({ |
| email: testEmail, |
| password: 'test123456' |
| }) |
| }); |
| const data = await res.json(); |
| log('β
Register response: ' + JSON.stringify(data, null, 2)); |
| } catch (err) { |
| log('β Register failed: ' + err.message, true); |
| } |
| } |
| |
| async function testLogin() { |
| log('Testing /api/users/login...'); |
| try { |
| const res = await fetch(API + '/users/login', { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify({ |
| email: 'admin@moharek.com', |
| password: 'admin123' |
| }) |
| }); |
| const data = await res.json(); |
| log('β
Login response: ' + JSON.stringify(data, null, 2)); |
| } catch (err) { |
| log('β Login failed: ' + err.message, true); |
| } |
| } |
| |
| |
| setTimeout(() => { |
| log('π Starting automatic tests...'); |
| testHealth(); |
| }, 500); |
| </script> |
| </body> |
| </html> |
|
|