155 lines
2.7 KiB
HTML
155 lines
2.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Docker Web App</title>
|
|
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
background: #f4f6f8;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
}
|
|
|
|
.container {
|
|
background: white;
|
|
padding: 30px;
|
|
border-radius: 12px;
|
|
width: 400px;
|
|
box-shadow: 0 10px 25px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
h1 {
|
|
text-align: center;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
input {
|
|
width: 100%;
|
|
padding: 10px;
|
|
margin-bottom: 10px;
|
|
border-radius: 8px;
|
|
border: 1px solid #ccc;
|
|
}
|
|
|
|
button {
|
|
width: 48%;
|
|
padding: 10px;
|
|
border: none;
|
|
border-radius: 8px;
|
|
cursor: pointer;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.add-btn {
|
|
background: #4CAF50;
|
|
color: white;
|
|
}
|
|
|
|
.load-btn {
|
|
background: #2196F3;
|
|
color: white;
|
|
}
|
|
|
|
button:hover {
|
|
opacity: 0.9;
|
|
}
|
|
|
|
.btn-group {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
ul {
|
|
list-style: none;
|
|
padding: 0;
|
|
}
|
|
|
|
li {
|
|
background: #eee;
|
|
padding: 10px;
|
|
margin-bottom: 5px;
|
|
border-radius: 6px;
|
|
}
|
|
|
|
.status {
|
|
text-align: center;
|
|
margin-top: 10px;
|
|
font-size: 14px;
|
|
color: green;
|
|
}
|
|
</style>
|
|
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container">
|
|
<h1>🚀 Docker App</h1>
|
|
|
|
<input id="name" placeholder="Enter name..." />
|
|
|
|
<div class="btn-group">
|
|
<button class="add-btn" onclick="add()">Add</button>
|
|
<button class="load-btn" onclick="load()">Load</button>
|
|
</div>
|
|
|
|
<ul id="list"></ul>
|
|
|
|
<div class="status" id="status"></div>
|
|
</div>
|
|
|
|
<script>
|
|
const API = "http://localhost:3000";
|
|
|
|
function add() {
|
|
const name = document.getElementById("name").value;
|
|
|
|
if (!name) {
|
|
setStatus("⚠️ Please enter a name", "red");
|
|
return;
|
|
}
|
|
|
|
fetch(API + "/add", {
|
|
method: "POST",
|
|
headers: {"Content-Type": "application/json"},
|
|
body: JSON.stringify({ name })
|
|
})
|
|
.then(() => {
|
|
setStatus("✅ Added successfully");
|
|
document.getElementById("name").value = "";
|
|
load();
|
|
})
|
|
.catch(() => setStatus("❌ Error adding data", "red"));
|
|
}
|
|
|
|
function load() {
|
|
fetch(API + "/items")
|
|
.then(res => res.json())
|
|
.then(data => {
|
|
const list = document.getElementById("list");
|
|
list.innerHTML = "";
|
|
|
|
data.forEach(item => {
|
|
const li = document.createElement("li");
|
|
li.innerText = item.name;
|
|
list.appendChild(li);
|
|
});
|
|
|
|
setStatus("📦 Data loaded");
|
|
})
|
|
.catch(() => setStatus("❌ Error loading data", "red"));
|
|
}
|
|
|
|
function setStatus(msg, color="green") {
|
|
const status = document.getElementById("status");
|
|
status.innerText = msg;
|
|
status.style.color = color;
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html> |