108 lines
2.3 KiB
HTML
108 lines
2.3 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Beranda</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 20px;
|
|
background-color: #f4f4f4;
|
|
color: #333;
|
|
}
|
|
|
|
h1 {
|
|
color: #2c3e50;
|
|
text-align: center;
|
|
}
|
|
|
|
p {
|
|
text-align: center;
|
|
font-size: 18px;
|
|
}
|
|
|
|
nav {
|
|
text-align: center;
|
|
margin-top: 30px;
|
|
}
|
|
|
|
nav a {
|
|
text-decoration: none;
|
|
color: #3498db;
|
|
margin: 0 10px;
|
|
font-weight: bold;
|
|
}
|
|
|
|
nav a:hover {
|
|
color: #1abc9c;
|
|
}
|
|
|
|
.user-list {
|
|
margin-top: 40px;
|
|
max-width: 600px;
|
|
margin-left: auto;
|
|
margin-right: auto;
|
|
}
|
|
|
|
.user-list ul {
|
|
list-style-type: none;
|
|
padding: 0;
|
|
}
|
|
|
|
.user-list li {
|
|
background-color: white;
|
|
margin: 5px 0;
|
|
padding: 10px;
|
|
border-radius: 5px;
|
|
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>Selamat Datang di Web App Docker!!</h1>
|
|
<p>Ini adalah halaman beranda.</p>
|
|
<nav>
|
|
<a href="/">Beranda</a> |
|
|
<a href="/about.html">Tentang</a>
|
|
</nav>
|
|
|
|
<div class="user-list">
|
|
<h2>Daftar Pengguna</h2>
|
|
<ul id="user-container">
|
|
<li>Memuat data...</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<script>
|
|
fetch('http://localhost:3000/users')
|
|
.then(async response => {
|
|
if (!response.ok) {
|
|
// Coba ambil pesan error dari response body
|
|
const errorText = await response.text();
|
|
throw new Error(`Gagal mengambil data (Status ${response.status}): ${errorText}`);
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(data => {
|
|
const container = document.getElementById('user-container');
|
|
container.innerHTML = ''; // Bersihkan placeholder
|
|
if (data.length === 0) {
|
|
container.innerHTML = '<li>Tidak ada data pengguna.</li>';
|
|
} else {
|
|
data.forEach(user => {
|
|
const li = document.createElement('li');
|
|
li.textContent = user.name || 'Tanpa Nama';
|
|
container.appendChild(li);
|
|
});
|
|
}
|
|
})
|
|
.catch(error => {
|
|
const container = document.getElementById('user-container');
|
|
container.innerHTML = `<li style="color: red;">Error: ${error.message}</li>`;
|
|
console.error('Detail error:', error); // ← tampil di browser console (F12)
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|