sergiodxa / remix-hono

Hono middlewares for Remix
MIT License
445 stars 10 forks source link

Infinite redirects at `/` #144

Closed gustavopch closed 8 months ago

gustavopch commented 9 months ago

The problem is here: https://github.com/sergiodxa/remix-hono/blob/582c0756d16971bf65ab5f151fa9d56bbb313c1b/src/trailing-slash.ts#L20-L23

When you're at /foo/, it strips down to /foo. But when you're at /, it can't be stripped. This should fix it:

-if (!options?.enabled && hasTrailingSlash) { 
+if (!options?.enabled && hasTrailingSlash && url.pathname !== '/') { 
   url.pathname = url.pathname.slice(0, -1); 
   return c.redirect(url.toString()); 
 } 
rphlmr commented 9 months ago

Nice catch!