This commit is contained in:
parent
3718e5a47f
commit
9082287ad3
5 changed files with 22 additions and 31 deletions
|
@ -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<string>(["plausible", "script"]);
|
||||
const cachedScript = await kvCache.get<string>(["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,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"m.homeserver": {
|
||||
"base_url": "https://matrix.chat.tjo.space"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"m.server": "matrix.chat.tjo.space:443"
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"contacts": [
|
||||
{
|
||||
"matrix_id": "@tine:tjo.space",
|
||||
"email_address": "tine@tjo.space",
|
||||
"role": "m.role.admin"
|
||||
},
|
||||
],
|
||||
"support_page": "https://tjo.space"
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue