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
/** @jsxImportSource npm:hono/jsx */
import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
import { blob } from "https://esm.town/v/std/blob?v=12";
import { Hono } from "npm:hono";
const app = new Hono();
const blobKey = `tinybase_example.json`;
app.get("/", (c) => {
// The client script is referenced in the page head
return c.html(
<html>
<head>
<title>Tinybase Example</title>
<link rel="stylesheet" href="https://unpkg.com/missing.css@1.1.1" />
<script type="module" src="https://esm.town/v/pomdtr/tinybase_example_client" />
</head>
<body></body>
</html>,
);
});
// The load endpoint will be polled periodically
app.get("/load", async (c) => {
const store = await blob.getJSON(blobKey);
return c.json(store);
});
// The save endpoint will be use to persist the store on change
app.post("/save", async (c) => {
await blob.setJSON(blobKey, await c.req.json());
return c.text("OK");
});
export default app.fetch;