import HttpRouter from "@src/router.ts"; import { Eta } from "@eta-dev/eta"; import { serveFile } from "jsr:@std/http/file-server"; import rateLimitMiddleware from "@src/middleware/rateLimiter.ts"; import authMiddleware from "@src/middleware/auth.ts"; const router = new HttpRouter(); const views = Deno.cwd() + "/views/"; const eta = new Eta({ views }); router.use(rateLimitMiddleware); router.use(authMiddleware); const filesToCache = new Set(["/public/js/shared.bundle.js"]); router.get("/public/*", async (c) => { const filePath = "." + c.path; const res = await serveFile(c.req, filePath); if (filesToCache.has(filePath)) { res.headers.set("Cache-Control", "public max-age=31536000"); } return res; }); router .get(["", "/index.html"], (c) => { return c.html(eta.render("./index.html", {})); }) .get(["/login", "/login.html"], (c) => { return c.html(eta.render("./login.html", {})); }) .post("/login", async (c) => { const body = await c.req.text(); console.log(JSON.parse(body)); return c.json({ mes: "got you" }); }); export default { async fetch(req, connInfo) { return await router.handleRequest(req, connInfo); }, } satisfies Deno.ServeDefaultExport;