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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { api } from "https://esm.town/v/pomdtr/api?v=9";
import {
authMiddlewareCookie,
signInFormBase,
userActionsDisplay,
} from "https://esm.town/v/postpostscript/authMiddleware";
import { html, htmlResponse, Layout } from "https://esm.town/v/postpostscript/htmlComponentLibrary";
import type { JWTPayload } from "https://esm.town/v/postpostscript/jwksUtils";
import { getValNameFromUrl } from "https://esm.town/v/postpostscript/meta";
import { MyFooter } from "https://esm.town/v/postpostscript/MyFooter";
import { readmeMarkdown } from "https://esm.town/v/postpostscript/readmeMarkdown";
import { type Context, Hono } from "npm:hono";
const app = new Hono();
const name = getValNameFromUrl(import.meta.url);
async function createPage(content: unknown) {
const [
footer,
readme,
] = await Promise.all([
MyFooter(),
readmeMarkdown(import.meta.url),
]);
return Layout`
<main>
${content}
<br>
<br>
<hr>
${readme}
<br>
</main>
${footer}
`.toString();
}
app.use(
"*",
authMiddlewareCookie<Context>({
verify: {
// by default this is `@[author of val]/authId`, meaning only the author can sign in
// setting it to undefined lets anyone sign in
issuer: undefined,
},
async createResponse(c, content, init) {
return c.html(createPage(content));
},
templates: {
signInForm: signInFormBase,
},
}),
);
app.get("/", async (c) => {
const payload = c.get("auth") as JWTPayload;
const userActions = userActionsDisplay(payload, {
order: ["language", "profile", "username", "emoji", "logout"],
parts: {
emoji: html`&nbsp;🎉`,
},
});
return c.html(createPage(userActions));
});
export default app.fetch;