blob: c72d766d88b3008e0bc5debe740942c898afa260 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import { serve } from "@hono/node-server";
import { Hono } from "hono";
import { createClient } from "@libsql/client";
import { drizzle } from "drizzle-orm/libsql";
import { groupsTable } from "./db/schema.js";
const app = new Hono();
const db = drizzle(createClient({ url: "file:data.db" }));
async function Groups() {
const result = await db.select().from(groupsTable).all();
return <ul>{
result.map(group => <li>{group.name}</li>)
}</ul>;
}
app.get("/", c => c.html(
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.6/dist/htmx.min.js" integrity="sha384-Akqfrbj/HpNVo8k11SXBb6TlBWmXXlYQrCSqEWmyKJe+hDm3Z/B2WVG4smwBkRVm" crossorigin="anonymous"></script>
<title>Uneven</title>
</head>
<body>
<Groups />
<button hx-get="/button" hx-swap="outerHTML">click me!</button>
</body>
</html>
));
let colors = ["red", "green", "blue"];
app.get("/button", c => c.html(
<button
hx-get="/button"
hx-swap="outerHTML"
style={{ backgroundColor: colors[Math.floor(Math.random() * colors.length)] }}
>disco button!</button>
));
serve({
fetch: app.fetch,
port: 3000,
}, info => console.log(`Server is running on http://localhost:${info.port}`));
|