174 lines
3.8 KiB
HTML
174 lines
3.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Kubernetes Demo App</title>
|
|
<style>
|
|
:root {
|
|
color-scheme: light;
|
|
--bg: #f4efe6;
|
|
--panel: #fffaf2;
|
|
--text: #1f2933;
|
|
--accent: #bf6d2c;
|
|
--accent-dark: #8e4b17;
|
|
--border: #e6d7c3;
|
|
}
|
|
|
|
* {
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
margin: 0;
|
|
min-height: 100vh;
|
|
font-family: "Trebuchet MS", "Segoe UI", sans-serif;
|
|
color: var(--text);
|
|
background:
|
|
radial-gradient(circle at top, rgba(191, 109, 44, 0.18), transparent 35%),
|
|
linear-gradient(180deg, #f8f2e9 0%, var(--bg) 100%);
|
|
display: grid;
|
|
place-items: center;
|
|
padding: 24px;
|
|
}
|
|
|
|
.card {
|
|
width: min(640px, 100%);
|
|
background: var(--panel);
|
|
border: 1px solid var(--border);
|
|
border-radius: 20px;
|
|
padding: 28px;
|
|
box-shadow: 0 20px 50px rgba(72, 49, 24, 0.12);
|
|
}
|
|
|
|
h1 {
|
|
margin-top: 0;
|
|
margin-bottom: 8px;
|
|
font-size: clamp(2rem, 5vw, 2.8rem);
|
|
}
|
|
|
|
p {
|
|
margin-top: 0;
|
|
color: #52606d;
|
|
}
|
|
|
|
.row {
|
|
display: flex;
|
|
gap: 12px;
|
|
flex-wrap: wrap;
|
|
margin: 24px 0;
|
|
}
|
|
|
|
input {
|
|
flex: 1 1 260px;
|
|
border: 1px solid var(--border);
|
|
border-radius: 12px;
|
|
padding: 14px 16px;
|
|
font-size: 1rem;
|
|
}
|
|
|
|
button {
|
|
border: 0;
|
|
border-radius: 12px;
|
|
padding: 14px 18px;
|
|
background: var(--accent);
|
|
color: white;
|
|
font-size: 1rem;
|
|
cursor: pointer;
|
|
transition: transform 0.15s ease, background 0.15s ease;
|
|
}
|
|
|
|
button:hover {
|
|
background: var(--accent-dark);
|
|
transform: translateY(-1px);
|
|
}
|
|
|
|
.status {
|
|
min-height: 24px;
|
|
margin-bottom: 12px;
|
|
color: var(--accent-dark);
|
|
font-weight: 600;
|
|
}
|
|
|
|
ul {
|
|
margin: 0;
|
|
padding-left: 20px;
|
|
}
|
|
|
|
li + li {
|
|
margin-top: 6px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<main class="card">
|
|
<h1>Kubernetes demo</h1>
|
|
<p>This frontend sends names to the backend API and loads them back from PostgreSQL running in a StatefulSet.</p>
|
|
|
|
<div class="row">
|
|
<input id="name" placeholder="Enter name">
|
|
<button onclick="sendAndLoad()">Save and show</button>
|
|
</div>
|
|
|
|
<div id="status" class="status"></div>
|
|
<ul id="list"></ul>
|
|
</main>
|
|
|
|
<script>
|
|
async function loadUsers() {
|
|
const status = document.getElementById("status");
|
|
|
|
try {
|
|
status.textContent = "Loading users...";
|
|
const res = await fetch("/api/users");
|
|
const data = await res.json();
|
|
|
|
const list = document.getElementById("list");
|
|
list.innerHTML = "";
|
|
|
|
data.forEach((user) => {
|
|
const li = document.createElement("li");
|
|
li.innerText = user.name;
|
|
list.appendChild(li);
|
|
});
|
|
|
|
status.textContent = "Users loaded successfully.";
|
|
} catch (error) {
|
|
console.error(error);
|
|
status.textContent = "Cannot connect to backend.";
|
|
}
|
|
}
|
|
|
|
async function sendAndLoad() {
|
|
const status = document.getElementById("status");
|
|
const nameInput = document.getElementById("name");
|
|
const name = nameInput.value.trim();
|
|
|
|
if (!name) {
|
|
status.textContent = "Please enter a name first.";
|
|
return;
|
|
}
|
|
|
|
try {
|
|
status.textContent = "Saving user...";
|
|
await fetch("/api/save", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json"
|
|
},
|
|
body: JSON.stringify({ name })
|
|
});
|
|
|
|
nameInput.value = "";
|
|
await loadUsers();
|
|
} catch (error) {
|
|
console.error(error);
|
|
status.textContent = "Saving failed.";
|
|
}
|
|
}
|
|
|
|
window.onload = loadUsers;
|
|
</script>
|
|
</body>
|
|
</html>
|