From ffc06bdb2aa3e547c1f7b07ed6a4865edeef1303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Xalambr=C3=AD?= Date: Wed, 17 Jan 2024 17:42:16 -0500 Subject: [PATCH 1/2] Redirect from www. to non www. --- server/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/index.ts b/server/index.ts index 6023581..92648e9 100644 --- a/server/index.ts +++ b/server/index.ts @@ -19,6 +19,13 @@ type ContextEnv = { Bindings: RuntimeEnv }; const server = new Hono(); +server.use("*", (context, next) => { + let url = new URL(context.req.url); + if (!url.origin.includes("www.")) return next(); + url.hostname = url.hostname.slice(4); + return c.redirect(url.href, 302); +}); + server.use("/write", (context, next) => { let { WRITE_PASSWORD } = EnvSchema.parse(context.env); return basicAuth({ username: "sergiodxa", password: WRITE_PASSWORD })( From 0dd585252307a29fd4075f99d7d50972ebded297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Xalambr=C3=AD?= Date: Wed, 17 Jan 2024 19:04:58 -0500 Subject: [PATCH 2/2] Fix runtime and TS --- server/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/index.ts b/server/index.ts index 92648e9..ab4dbbd 100644 --- a/server/index.ts +++ b/server/index.ts @@ -19,11 +19,11 @@ type ContextEnv = { Bindings: RuntimeEnv }; const server = new Hono(); -server.use("*", (context, next) => { +server.use("*", async (context, next) => { let url = new URL(context.req.url); if (!url.origin.includes("www.")) return next(); url.hostname = url.hostname.slice(4); - return c.redirect(url.href, 302); + return context.redirect(url.href, 302); }); server.use("/write", (context, next) => {