zero-knowledge file sharing
at main 38 lines 878 B view raw
1import { Hono } from "hono"; 2import { serveStatic } from "hono/bun"; 3 4import { config } from "./config.ts"; 5import { cleanExpired } from "./db.ts"; 6import file from "./file.ts"; 7 8const app = new Hono(); 9 10app.route("/api/file", file); 11 12app.get("/api/info", (c) => { 13 return c.json({ 14 maxFileSize: config.maxFileSize, 15 maxTtl: config.maxTtl, 16 }); 17}); 18 19app.use("/*", serveStatic({ root: "./web/dist" })); 20 21// SPA catch-all: serve index.html for unmatched routes 22app.get("/*", () => { 23 return new Response(Bun.file("web/dist/index.html"), { 24 headers: { "Content-Type": "text/html; charset=utf-8" }, 25 }); 26}); 27 28// Clean expired uploads every 5 minutes 29setInterval(cleanExpired, 5 * 60 * 1000); 30 31const port = config.port; 32console.log(`Server running on http://localhost:${port}`); 33 34export default { 35 port, 36 maxRequestBodySize: config.maxFileSize, 37 fetch: app.fetch, 38};