server for API tests
This commit is contained in:
71
server-api/public/index.html
Normal file
71
server-api/public/index.html
Normal file
@@ -0,0 +1,71 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>API Dashboard</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>🎛️ Pannello di Controllo API</h1>
|
||||
|
||||
<div class="server-info">
|
||||
<p>Il server è attivo.</p>
|
||||
<p>Indirizzo Base: <strong id="base-url">...</strong></p>
|
||||
</div>
|
||||
|
||||
<div id="container">Loading resources...</div>
|
||||
|
||||
<script>
|
||||
const container = document.getElementById('container');
|
||||
const baseUrlDisplay = document.getElementById('base-url');
|
||||
|
||||
// Imposta l'URL base dinamico (così funziona sia su localhost che su IP di rete)
|
||||
const BASE_URL = window.location.origin;
|
||||
baseUrlDisplay.innerText = BASE_URL;
|
||||
|
||||
async function scanDatabase() {
|
||||
try {
|
||||
const response = await fetch(`${BASE_URL}/api`);
|
||||
const data = await response.json();
|
||||
|
||||
container.innerHTML = '';
|
||||
|
||||
for (const [key, _] of Object.entries(data)) {
|
||||
createResourceCard(key);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
container.innerHTML = `<h3 style="color:red">Errore di connessione al DB: ${error.message}</h3>`;
|
||||
}
|
||||
}
|
||||
|
||||
async function createResourceCard(name) {
|
||||
const url = `${BASE_URL}/api/${name}`;
|
||||
const sample = await fetch(url + "/1").catch(() => null);
|
||||
const sampleJson = sample ? await sample.json() : "Nessun dato!";
|
||||
|
||||
const html = `
|
||||
<div class="resource-card">
|
||||
<div class="resource-header">
|
||||
<span class="resource-name">/${name}</span>
|
||||
</div>
|
||||
<p>Endpoint per richieste GET, POST, ecc:</p>
|
||||
<div class="url-box">${url}</div>
|
||||
|
||||
<h4>Esempio Risultato:</h4>
|
||||
<div class="code-label">GET ${url}/1</div>
|
||||
<div class="preview">${JSON.stringify(sampleJson, null, 2)}</div>
|
||||
</div>
|
||||
`;
|
||||
container.innerHTML += html;
|
||||
}
|
||||
|
||||
// Avvio scansione
|
||||
scanDatabase();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
85
server-api/public/styles.css
Normal file
85
server-api/public/styles.css
Normal file
@@ -0,0 +1,85 @@
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
background: #f4f4f9;
|
||||
padding: 20px;
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.server-info {
|
||||
background: #333;
|
||||
color: white;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.resource-card {
|
||||
background: white;
|
||||
border: 1px solid #ddd;
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.resource-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
border-bottom: 2px solid #eee;
|
||||
padding-bottom: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.resource-name {
|
||||
font-size: 1.5em;
|
||||
font-weight: bold;
|
||||
color: #007bff;
|
||||
}
|
||||
|
||||
.resource-count {
|
||||
background: #eee;
|
||||
padding: 5px 10px;
|
||||
border-radius: 12px;
|
||||
font-size: 0.9em;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.url-box {
|
||||
background: #2d2d2d;
|
||||
color: #76ff03;
|
||||
padding: 10px;
|
||||
font-family: monospace;
|
||||
border-radius: 4px;
|
||||
margin-top: 10px;
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.preview {
|
||||
background: #f9f9f9;
|
||||
padding: 10px;
|
||||
border-left: 4px solid #007bff;
|
||||
margin-top: 15px;
|
||||
font-family: monospace;
|
||||
font-size: 0.9em;
|
||||
white-space: pre-wrap;
|
||||
overflow-x: auto;
|
||||
max-height: 200px;
|
||||
}
|
||||
|
||||
.code-label {
|
||||
font-size: 0.85em;
|
||||
color: #555;
|
||||
margin-top: 15px;
|
||||
margin-bottom: 5px;
|
||||
font-family: monospace;
|
||||
}
|
||||
Reference in New Issue
Block a user