withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
47.26k stars 2.51k forks source link

Issue with Trailing Slashes in URLs Preventing Middleware Execution in Astro #12537

Open rajpatel2435 opened 6 days ago

rajpatel2435 commented 6 days ago

Hello @tordans @altano @madbook

Astro Info

Astro                    v4.5.2
Node                     v20.9.0
System                   Windows (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/tailwind

If this issue only occurs in one browser, which browser is a problem?

All Browser

Describe the Bug

When accessing URLs with multiple trailing slashes, such as:

https://vegasaces.com/games/slots/lucky-dama-muerta////////// The URL is automatically normalized in the backend to:

/games/slots/lucky-dama-muerta/

However, this normalization seems to bypass middleware logic. As a result, middleware doesn't execute as expected for the raw incoming URL.

Steps to Reproduce:

Create an Astro project with a middleware to log requests or process specific slugs. Access a URL with multiple trailing slashes (e.g., //////////). Observe that the middleware does not execute correctly for the normalized path.

What's the expected result?

Astro should identify and process URLs with multiple trailing slashes correctly, ensuring middleware functions execute as intended.

Current Behavior: URLs with trailing slashes are normalized by Astro, but middleware logic does not handle the original raw URL, causing inconsistencies.

Link to Minimal Reproducible Example

https://vegasaces.com/games/slots/lucky-dama-muerta//////////

Participation

ascorbic commented 3 days ago

Hi. It's not totally clear to me what you mean when you say the middleware is not executed correctly. Is it not executed at all, or in the wrong way? If the latter, wrong in what way. Can you provide a reproduction that includes the source code, ideally via stackblitz. Thanks

github-actions[bot] commented 3 days ago

Hello @rajpatel2435. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

rajpatel2435 commented 1 day ago

Hi @ascorbic

Issue is that when I type in browser with multiple trailing slashes

https://vegasaces.com/games/slots/////////

in Astro logs terminal I just got https://vegasaces.com/games/slots/

how can I fix that so I only have one trailing slashes in the end of URL?

https://github.com/rajpatel2435/Slotsparadise_Astro

Thanks

ascorbic commented 14 hours ago

That's not something we can use as a minimal reproduction. Please create a minimal reproduction, ideally using astro.new and Stackblitz.

rajpatel2435 commented 5 hours ago

Hi @ascorbic

image

https://stackblitz.com/~/github.com/rajpatel2435/Slotsparadise_Astro?file=src/layouts/Layout.astro&initialPath=/casino/slots/////////////////////////

why in Astro terminal we are not getting URL with multiple trailing slash?

Thanks

ascorbic commented 4 hours ago

That link shows a 404 page for me. Please see the instructions on creating a minimal reproduction. Please don't just share your whole site: you need to narrow it to the smallest example that reproduces the problem. It's usually best to start from a starter site rather than from your own site.

rajpatel2435 commented 4 hours ago

Hi @ascorbic

This is the minimal project structure

https://stackblitz.com/~/github.com/rajpatel2435/slots?file=.env&initialPath=/how-to-play///

Thanks