Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task
rajpatel2435 opened this issue Nov 26, 2024 · 12 comments
Closed
1 task
Labels
feat: middleware Related to middleware (scope) needs triage Issue needs to be triaged

Comments

@rajpatel2435
Copy link

rajpatel2435 commented Nov 26, 2024

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

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Nov 26, 2024
@ascorbic
Copy link
Contributor

ascorbic commented Nov 29, 2024

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

@ascorbic ascorbic added needs repro Issue needs a reproduction feat: middleware Related to middleware (scope) and removed needs triage Issue needs to be triaged labels Nov 29, 2024
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

ascorbic commented Dec 2, 2024

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

@rajpatel2435
Copy link
Author

rajpatel2435 commented Dec 2, 2024

@ascorbic
Copy link
Contributor

ascorbic commented Dec 2, 2024

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
Copy link
Author

@ascorbic
Copy link
Contributor

ascorbic commented Dec 3, 2024

That project has no middleware, so I don't know how you can reproduce a bug. Can you please start from an empty project from https://astro.new/basics and add just the parts needed to demonstrate the bug.

@rajpatel2435
Copy link
Author

Hi @bluwy @ascorbic

I updated the repo with middleware but you did not get my point correctly. the issue is that in terminal we are not getting the actual url that we are writing in browsers so our middleware is not able to get the correct url from the frontend.

for example here in browser i am writing /how-to-play///////////// but i n terminal we are getting /how-to-play/ but in actual what we need is the backend will get the correct url what we are writing in the frontend

image
are u able to see difference here?

Thanks

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 9, 2024
@ematipico ematipico added needs triage Issue needs to be triaged and removed needs repro Issue needs a reproduction labels Dec 9, 2024
@ematipico ematipico reopened this Dec 9, 2024
@rajpatel2435
Copy link
Author

Hi @ematipico

is there any update on this?

Thanks

@ematipico
Copy link
Member

Sorry @rajpatel2435 , but your reproduction isn't minimal, please provide one

@rajpatel2435
Copy link
Author

Solved from my side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: middleware Related to middleware (scope) needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

3 participants