183 lines
6.7 KiB
HTML
183 lines
6.7 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="ru">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Тест подключения MC Panel</title>
|
||
<style>
|
||
body {
|
||
font-family: Arial, sans-serif;
|
||
max-width: 800px;
|
||
margin: 50px auto;
|
||
padding: 20px;
|
||
background: #1a1a1a;
|
||
color: #fff;
|
||
}
|
||
.test {
|
||
background: #2a2a2a;
|
||
padding: 15px;
|
||
margin: 10px 0;
|
||
border-radius: 5px;
|
||
border-left: 4px solid #666;
|
||
}
|
||
.test.success {
|
||
border-left-color: #4caf50;
|
||
}
|
||
.test.error {
|
||
border-left-color: #f44336;
|
||
}
|
||
button {
|
||
background: #2196F3;
|
||
color: white;
|
||
border: none;
|
||
padding: 10px 20px;
|
||
border-radius: 5px;
|
||
cursor: pointer;
|
||
font-size: 16px;
|
||
}
|
||
button:hover {
|
||
background: #1976D2;
|
||
}
|
||
pre {
|
||
background: #000;
|
||
padding: 10px;
|
||
border-radius: 5px;
|
||
overflow-x: auto;
|
||
}
|
||
.info {
|
||
background: #333;
|
||
padding: 15px;
|
||
border-radius: 5px;
|
||
margin-bottom: 20px;
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<h1>🔧 Тест подключения MC Panel</h1>
|
||
|
||
<div class="info">
|
||
<h3>Информация о подключении:</h3>
|
||
<p><strong>Текущий URL:</strong> <span id="currentUrl"></span></p>
|
||
<p><strong>API URL:</strong> <span id="apiUrl"></span></p>
|
||
<p><strong>WebSocket URL:</strong> <span id="wsUrl"></span></p>
|
||
</div>
|
||
|
||
<button onclick="runTests()">▶️ Запустить тесты</button>
|
||
|
||
<div id="results"></div>
|
||
|
||
<script>
|
||
const protocol = window.location.protocol;
|
||
const hostname = window.location.hostname || 'localhost';
|
||
const apiUrl = `${protocol}//${hostname}:8000`;
|
||
const wsUrl = apiUrl.replace('http', 'ws');
|
||
|
||
document.getElementById('currentUrl').textContent = window.location.href;
|
||
document.getElementById('apiUrl').textContent = apiUrl;
|
||
document.getElementById('wsUrl').textContent = wsUrl;
|
||
|
||
async function runTests() {
|
||
const results = document.getElementById('results');
|
||
results.innerHTML = '<h2>Результаты тестов:</h2>';
|
||
|
||
// Тест 1: Проверка доступности API
|
||
await testEndpoint('GET', '/api/servers', 'Получение списка серверов');
|
||
|
||
// Тест 2: Создание тестового сервера
|
||
const serverName = 'test_' + Date.now();
|
||
const created = await testEndpoint('POST', '/api/servers/create', 'Создание тестового сервера', {
|
||
name: serverName,
|
||
displayName: 'Тестовый сервер',
|
||
startCommand: 'java -Xmx1G -Xms1G -jar server.jar nogui'
|
||
});
|
||
|
||
if (created) {
|
||
// Тест 3: Получение конфигурации
|
||
await testEndpoint('GET', `/api/servers/${serverName}/config`, 'Получение конфигурации сервера');
|
||
|
||
// Тест 4: Получение файлов
|
||
await testEndpoint('GET', `/api/servers/${serverName}/files`, 'Получение списка файлов');
|
||
|
||
// Тест 5: Удаление тестового сервера
|
||
await testEndpoint('DELETE', `/api/servers/${serverName}`, 'Удаление тестового сервера');
|
||
}
|
||
|
||
// Тест 6: WebSocket
|
||
testWebSocket();
|
||
}
|
||
|
||
async function testEndpoint(method, path, description, body = null) {
|
||
const div = document.createElement('div');
|
||
div.className = 'test';
|
||
div.innerHTML = `<strong>${description}</strong><br>`;
|
||
document.getElementById('results').appendChild(div);
|
||
|
||
try {
|
||
const options = {
|
||
method: method,
|
||
headers: {
|
||
'Content-Type': 'application/json'
|
||
}
|
||
};
|
||
|
||
if (body) {
|
||
options.body = JSON.stringify(body);
|
||
}
|
||
|
||
const response = await fetch(`${apiUrl}${path}`, options);
|
||
const data = await response.json();
|
||
|
||
if (response.ok) {
|
||
div.className = 'test success';
|
||
div.innerHTML += `✅ Успешно (${response.status})<br>`;
|
||
div.innerHTML += `<pre>${JSON.stringify(data, null, 2)}</pre>`;
|
||
return true;
|
||
} else {
|
||
div.className = 'test error';
|
||
div.innerHTML += `❌ Ошибка (${response.status})<br>`;
|
||
div.innerHTML += `<pre>${JSON.stringify(data, null, 2)}</pre>`;
|
||
return false;
|
||
}
|
||
} catch (error) {
|
||
div.className = 'test error';
|
||
div.innerHTML += `❌ Ошибка подключения: ${error.message}`;
|
||
return false;
|
||
}
|
||
}
|
||
|
||
function testWebSocket() {
|
||
const div = document.createElement('div');
|
||
div.className = 'test';
|
||
div.innerHTML = `<strong>Тест WebSocket подключения</strong><br>`;
|
||
document.getElementById('results').appendChild(div);
|
||
|
||
try {
|
||
const ws = new WebSocket(`${wsUrl}/ws/servers/test/console`);
|
||
|
||
ws.onopen = () => {
|
||
div.className = 'test success';
|
||
div.innerHTML += `✅ WebSocket подключен успешно`;
|
||
ws.close();
|
||
};
|
||
|
||
ws.onerror = (error) => {
|
||
div.className = 'test error';
|
||
div.innerHTML += `❌ Ошибка WebSocket: ${error}`;
|
||
};
|
||
|
||
setTimeout(() => {
|
||
if (ws.readyState !== WebSocket.OPEN) {
|
||
div.className = 'test error';
|
||
div.innerHTML += `❌ WebSocket не подключился за 5 секунд`;
|
||
ws.close();
|
||
}
|
||
}, 5000);
|
||
} catch (error) {
|
||
div.className = 'test error';
|
||
div.innerHTML += `❌ Ошибка создания WebSocket: ${error.message}`;
|
||
}
|
||
}
|
||
</script>
|
||
</body>
|
||
</html>
|