From 817441f01da0b25c6af4096904d9984fda32c7ea Mon Sep 17 00:00:00 2001 From: Jonas Perusquia Morales Date: Mon, 13 Jul 2026 12:39:05 -0600 Subject: [PATCH] chore: add middleware to normalize trailing slashes in routes --- app/src/modules/server/AppServer.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/src/modules/server/AppServer.ts b/app/src/modules/server/AppServer.ts index 8352982e..722c9c33 100644 --- a/app/src/modules/server/AppServer.ts +++ b/app/src/modules/server/AppServer.ts @@ -55,6 +55,21 @@ export class AppServer extends Module { const origin = this.config.cors.origin ?? "*"; const origins = origin.includes(",") ? origin.split(",").map((o) => o.trim()) : [origin]; const all_origins = origins.includes("*"); + + // Normalize trailing slashes so that /admin/ matches /admin. + // Hono's app.route doesn't match trailing slashes; host frameworks + // like Nuxt/Nitro redirect /admin -> /admin/. When running standalone + // we emit a 308 ourselves so the route layer sees a clean path without + // re-running the middleware chain (which would re-consume c.req.raw). + this.client.use("*", async (c, next) => { + const url = new URL(c.req.url); + if (url.pathname.length > 1 && url.pathname.endsWith("/")) { + url.pathname = url.pathname.replace(/\/+$/, ""); + return c.redirect(url.toString(), 308); + } + return next(); + }); + this.client.use( "*", cors({