106 lines
3.2 KiB
HTML
106 lines
3.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title>Frontend</title>
|
|
<style>
|
|
#messageDisplay {
|
|
margin-top: 20px;
|
|
padding: 10px;
|
|
border: 1px solid #ccc;
|
|
border-radius: 5px;
|
|
min-height: 50px;
|
|
background-color: #f9f9f9;
|
|
}
|
|
button {
|
|
margin-right: 10px;
|
|
padding: 8px 12px;
|
|
background-color: #4CAF50;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
}
|
|
button:hover {
|
|
background-color: #45a049;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>Mini Frontend</h1>
|
|
<h2>Test CI</h2>
|
|
<button onclick="sendMessage()">Invia Messaggio</button>
|
|
<button onclick="retrieveMessage()">Recupera Messaggio</button>
|
|
<button onclick="checkQueueInfo()">Verifica Stato Coda</button>
|
|
|
|
<div id="messageDisplay">
|
|
<p>I messaggi recuperati appariranno qui...</p>
|
|
</div>
|
|
|
|
<script>
|
|
async function sendMessage() {
|
|
try {
|
|
const response = await fetch('/api/enqueue', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({ message: 'Hello from frontend!' })
|
|
});
|
|
const data = await response.json();
|
|
alert('Messaggio inviato alla coda!');
|
|
} catch (error) {
|
|
console.error('Errore nell\'invio del messaggio:', error);
|
|
alert('Errore nell\'invio del messaggio!');
|
|
}
|
|
}
|
|
|
|
async function retrieveMessage() {
|
|
try {
|
|
const response = await fetch('/api/messages');
|
|
const data = await response.json();
|
|
|
|
const displayDiv = document.getElementById('messageDisplay');
|
|
|
|
if (data.status === 'success') {
|
|
displayDiv.innerHTML = `
|
|
<h3>Messaggio recuperato:</h3>
|
|
<pre>${JSON.stringify(data.message, null, 2)}</pre>
|
|
`;
|
|
} else if (data.status === 'empty') {
|
|
displayDiv.innerHTML = `<p>Nessun messaggio disponibile nella coda.</p>`;
|
|
} else {
|
|
displayDiv.innerHTML = `<p>Errore: ${data.message}</p>`;
|
|
}
|
|
} catch (error) {
|
|
console.error('Errore nel recupero del messaggio:', error);
|
|
document.getElementById('messageDisplay').innerHTML =
|
|
`<p>Errore nella connessione al backend: ${error.message}</p>`;
|
|
}
|
|
}
|
|
|
|
async function checkQueueInfo() {
|
|
try {
|
|
const response = await fetch('/api/queue-info');
|
|
const data = await response.json();
|
|
|
|
const displayDiv = document.getElementById('messageDisplay');
|
|
|
|
if (data.status === 'success') {
|
|
displayDiv.innerHTML = `
|
|
<h3>Informazioni Coda:</h3>
|
|
<p>Nome: ${data.queue}</p>
|
|
<p>Messaggi in coda: ${data.messageCount}</p>
|
|
<p>Consumatori attivi: ${data.consumerCount}</p>
|
|
<pre>Proprietà complete: ${JSON.stringify(data.properties, null, 2)}</pre>
|
|
`;
|
|
} else {
|
|
displayDiv.innerHTML = `<p>Errore: ${data.message}</p>`;
|
|
}
|
|
} catch (error) {
|
|
console.error('Errore nel recupero info coda:', error);
|
|
document.getElementById('messageDisplay').innerHTML =
|
|
`<p>Errore nella connessione al backend: ${error.message}</p>`;
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |