1// This is the main file for paperclover.net's server.
2const app = new Hono();
3const console = log.scoped("http");
4
5// Middleware
6app.use(trimTrailingSlash());
7app.use(removeDuplicateSlashes);
8app.use(logger((msg) => msg.startsWith("-->") && console.info(msg.slice(4))));
9app.use(admin.middleware);
10
11// Backends
12app.route("", blog.app);
13app.route("", qa.app);
14app.route("", fileViewer.app);
15app.route("", friendAuth.app);
16app.route("", databases.app);
17app.route("", extra.app);
18
19// Asset middleware has least precedence
20app.use(assets.middleware);
21
22// Asset Aliases
23app.get(
24 "/apple-touch-icon-precomposed.png",
25 (c) => assets.serveAsset(c, "/apple-touch-icon.png"),
26);
27app.get(
28 "/apple-touch-icon-57x57.png",
29 (c) => assets.serveAsset(c, "/apple-touch-icon.png"),
30);
31app.get(
32 "/apple-touch-icon-57x57-precomposed.png",
33 (c) => assets.serveAsset(c, "/apple-touch-icon.png"),
34);
35
36// Redirects
37app.get(
38 "/hotewig-reanimated",
39 (c) =>
40 c.redirect(
41 "https://docs.google.com/forms/d/e/1FAIpQLSdMdwotGKmrDYT8stYPm5uoOlmqZPLApYp8MuABDmcAwW6Fig/viewform?usp=header",
42 ),
43);
44
45// Handlers
46app.notFound(assets.notFound);
47
48export default app;
49
50async function removeDuplicateSlashes(c: Context, next: Next) {
51 const path = c.req.path;
52 if (/\/\/+/.test(path)) {
53 const normalizedPath = path.replace(/\/\/+/g, "/");
54 const query = c.req.query();
55 const queryString = Object.keys(query).length > 0
56 ? "?" + new URLSearchParams(query).toString()
57 : "";
58 return c.redirect(normalizedPath + queryString, 301);
59 }
60 await next();
61}
62
63import * as assets from "#sitegen/assets";
64import * as log from "@clo/lib/log";
65import { type Context, Hono, type Next } from "hono";
66import { logger } from "hono/logger";
67import { trimTrailingSlash } from "hono/trailing-slash";
68import * as admin from "./admin.ts";
69import * as extra from "./backend-extra.ts";
70import * as blog from "./blog/backend.ts";
71import * as databases from "./databases.ts";
72import * as fileViewer from "./file-viewer/backend.ts";
73import "./file-viewer/sync.ts";
74import * as friendAuth from "./friend-auth.ts";
75import * as qa from "./q+a/backend.ts";