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: {
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` 🎉`,
},
});
return c.html(createPage(userActions));
});
export default app.fetch;