import type { MiddlewareHandler } from "hono"; export const canonicalizeTrailingSlash: MiddlewareHandler = async (context, next) => { const path = context.req.path; const method = context.req.method; if ((method === "GET" || method === "HEAD") && path !== "/" && path.endsWith("/")) { const { search } = new URL(context.req.url); return context.redirect(`${path.slice(0, -1)}${search}`, 301); } await next(); };