diff --git a/server/server.ts b/server/server.ts index f9d13d1..9532004 100644 --- a/server/server.ts +++ b/server/server.ts @@ -2,17 +2,35 @@ import { Hono } from "https://deno.land/x/hono@v4.2.5/mod.ts"; import { serveStatic, logger, + cors, + etag, + secureHeaders, + cache, } from "https://deno.land/x/hono@v4.2.5/middleware.ts"; -const cache = await Deno.openKv(); const app = new Hono(); app.use(logger()); +app.use(etag()); +app.use(secureHeaders()); +app.use( + cache({ + cacheName: "tjo-space", + cacheControl: "public, max-age=3600", + wait: true, + }), +); + +// Allow CORS for tjo.space +app.use(cors({ origin: "https://tjo.space" })); +// But, /.well-known requests from anywhere. +app.use("/.well-known/*", cors({ origin: "*" })); // .well-known for matrix app.get("/.well-known/matrix/client", (c) => c.json({ "m.homeserver": { base_url: "https://matrix.chat.tjo.space", + server_name: "tjo.space", }, }), ); @@ -58,12 +76,13 @@ app.get("/.well-known/webfinger", (c) => { }); }); +const kvCache = await Deno.openKv(); // Serve plausible analytics app.get("/js/script.js", async (c) => { c.header("Content-Type", "text/javascript"); // Check if we have the script cached - const cachedScript = await cache.get(["plausible", "script"]); + const cachedScript = await kvCache.get(["plausible", "script"]); if (cachedScript.value) { return c.body(cachedScript.value); } @@ -73,7 +92,7 @@ app.get("/js/script.js", async (c) => { // Cache for 24 hours if we got the script if (response.status === 200) { - await cache.set(["plausible", "script"], script, { + await kvCache.set(["plausible", "script"], script, { expireIn: 1000 * 60 * 60 * 24, }); } diff --git a/web/static/.well-known/matrix/client b/web/static/.well-known/matrix/client deleted file mode 100644 index ce65b5c..0000000 --- a/web/static/.well-known/matrix/client +++ /dev/null @@ -1,6 +0,0 @@ -{ - "m.homeserver": { - "base_url": "https://matrix.chat.tjo.space" - } -} - diff --git a/web/static/.well-known/matrix/server b/web/static/.well-known/matrix/server deleted file mode 100644 index d3e11f6..0000000 --- a/web/static/.well-known/matrix/server +++ /dev/null @@ -1,3 +0,0 @@ -{ - "m.server": "matrix.chat.tjo.space:443" -} diff --git a/web/static/.well-known/matrix/support b/web/static/.well-known/matrix/support deleted file mode 100644 index 3e91187..0000000 --- a/web/static/.well-known/matrix/support +++ /dev/null @@ -1,10 +0,0 @@ -{ - "contacts": [ - { - "matrix_id": "@tine:tjo.space", - "email_address": "tine@tjo.space", - "role": "m.role.admin" - }, - ], - "support_page": "https://tjo.space" -} diff --git a/web/static/.well-known/webfinger b/web/static/.well-known/webfinger deleted file mode 100644 index 2feb453..0000000 --- a/web/static/.well-known/webfinger +++ /dev/null @@ -1,9 +0,0 @@ -{ - "subject": "acct:tine@tjo.space", - "links": [ - { - "rel": "http://openid.net/specs/connect/1.0/issuer", - "href": "https://id.tjo.space/application/o/tailscalecom/.well-known/openid-configuration" - } - ] -}