Match Lucee UI and dedupe inserts
This commit is contained in:
parent
6e8edaad61
commit
af2d705c30
58
server.js
58
server.js
@ -67,18 +67,53 @@ function renderPage(rows, error) {
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>NodeJS + Postgres Demo</title>
|
||||
<link rel="icon" href="https://nubes.ru/themes/custom/nubes/images/nubes-ico.svg" type="image/svg+xml">
|
||||
<style>
|
||||
:root { --nubes-blue: #005BFF; --nubes-dark: #1A1A1A; --nubes-grey: #F8F9FA; --nubes-border: #E5E7EB; }
|
||||
body { font-family: 'Segoe UI', Tahoma, sans-serif; margin: 0; padding: 0; background: var(--nubes-grey); color: var(--nubes-dark); }
|
||||
.header-bg { position: sticky; top: 0; z-index: 1000; background: #fff; border-bottom: 1px solid var(--nubes-border); padding: 15px 0; box-shadow: 0 2px 10px rgba(0,0,0,0.05); }
|
||||
.container { max-width: 1000px; margin: auto; padding: 0 20px; }
|
||||
.header-content { display: flex; align-items: center; justify-content: space-between; }
|
||||
.logo { height: 40px; }
|
||||
.main-content { padding: 40px 0; }
|
||||
.card { background: #fff; padding: 32px; border-radius: 16px; box-shadow: 0 4px 20px rgba(0,0,0,0.04); }
|
||||
.btn { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 12px 24px; border: none; border-radius: 8px; font-weight: 600; font-size: 14px; }
|
||||
.btn-primary { background: var(--nubes-blue); color: #fff; }
|
||||
.btn-action { padding: 12px; background: #fff; border: 1px solid var(--nubes-border); border-radius: 8px; font-size: 18px; line-height: 1; cursor: pointer; min-width: 44px; }
|
||||
.btn-action:hover { background: var(--nubes-grey); border-color: var(--nubes-blue); }
|
||||
.input-group { display: flex; gap: 12px; margin-bottom: 32px; }
|
||||
input[type="text"] { flex-grow: 1; padding: 12px 16px; border: 1px solid var(--nubes-border); border-radius: 8px; font-size: 14px; }
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
th { text-align: left; padding: 16px; font-size: 12px; text-transform: uppercase; color: #6B7280; border-bottom: 1px solid var(--nubes-border); }
|
||||
td { padding: 16px; border-bottom: 1px solid var(--nubes-border); }
|
||||
tbody tr:nth-child(even) { background-color: #FAFBFC; }
|
||||
tbody tr:hover { background-color: #F3F4F6; }
|
||||
.id-cell { font-family: monospace; color: #9CA3AF; width: 60px; }
|
||||
.actions-cell { display: flex; gap: 12px; width: 130px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h3>NodeJS + Postgres Demo</h3>
|
||||
<div class="header-bg">
|
||||
<div class="container header-content">
|
||||
<img src="https://nubes.ru/themes/custom/nubes_2025/logo.svg" alt="Nubes" class="logo">
|
||||
<div style="font-size: 14px; color: var(--nubes-blue); font-weight: 600;">NodeJS + Postgres Demo</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container main-content">
|
||||
<div class="card">
|
||||
${errorHtml}
|
||||
<form method="POST" action="/add">
|
||||
<input type="text" name="txt_content" placeholder="New message">
|
||||
<button type="submit">Add</button>
|
||||
<form method="POST" action="/add" class="input-group" onsubmit="const btn=this.querySelector('button'); if(btn){btn.disabled=true; btn.textContent='Adding...';}">
|
||||
<input type="text" name="txt_content" placeholder="New message" required>
|
||||
<button type="submit" class="btn btn-primary">Add</button>
|
||||
</form>
|
||||
<table border="1" cellpadding="6" cellspacing="0">
|
||||
<tr><th>ID</th><th>Content</th><th>Actions</th></tr>
|
||||
<table>
|
||||
<thead><tr><th>ID</th><th>Content</th><th>Actions</th></tr></thead>
|
||||
<tbody>
|
||||
${rowsHtml}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
@ -118,8 +153,19 @@ async function handleRequest(req, res) {
|
||||
await ensureTable();
|
||||
if (url.pathname === "/add") {
|
||||
const content = form.txt_content || "Node did it";
|
||||
const { rows: lastRows } = await pool.query(
|
||||
"SELECT test_data, created_at FROM nubes_test_table ORDER BY id DESC LIMIT 1"
|
||||
);
|
||||
const last = lastRows[0];
|
||||
const isDuplicate =
|
||||
last &&
|
||||
last.test_data === content &&
|
||||
Date.now() - new Date(last.created_at).getTime() < 3000;
|
||||
|
||||
if (!isDuplicate) {
|
||||
await pool.query("INSERT INTO nubes_test_table (test_data) VALUES ($1)", [content]);
|
||||
}
|
||||
}
|
||||
if (url.pathname === "/update") {
|
||||
await pool.query("UPDATE nubes_test_table SET test_data=$1 WHERE id=$2", [
|
||||
form.txt_content || "",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user