Skip to content

fix: update redirect logic for URLs ending with '/'#2255

Closed
bjohansebas wants to merge 11 commits intomainfrom
send-fix
Closed

fix: update redirect logic for URLs ending with '/'#2255
bjohansebas wants to merge 11 commits intomainfrom
send-fix

Conversation

@bjohansebas
Copy link
Copy Markdown
Member

Summary

Okay, this took me a bit of time to understand. This is something similar to what send does. After several attempts, it can probably be refactored even more, but this would be the main solution.

The send workflow is: if it detects a trailing slash at the end of pathname ("/") (line of code), then it goes into another code path, where it joins the original pathname and appends the index (line of code which is configurable, just like in this package). When they are joined, if such an index file exists, it continues with the normal workflow, otherwise, it throws an error, similar to what is handled here. The difference is that now, if there is a trailing slash, the index file (which is configurable) is also appended

What kind of change does this PR introduce?

Did you add tests for your changes?

Does this PR introduce a breaking change?

yes!

If relevant, what needs to be documented once your changes are merged or what have you already documented?

bjohansebas and others added 6 commits January 27, 2026 14:57
* feat: enable cacheImmutable by default

* fix: thoses files shouldn't immutable

* fix: update cache control logic

becauses undefined !== false (true)

* test: add tests for cacheControl option behavior with cacheImmutable set to false

* refactor: normalize cacheControl handling in response headers

* refactor: simplify maxAge calculation in cacheControl handling
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 27, 2026

Codecov Report

❌ Patch coverage is 96.77419% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.70%. Comparing base (43f22c4) to head (ee8725d).
⚠️ Report is 56 commits behind head on main.

Files with missing lines Patch % Lines
src/middleware.js 97.22% 1 Missing ⚠️
src/utils/getFilenameFromUrl.js 95.83% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2255      +/-   ##
==========================================
- Coverage   95.88%   95.70%   -0.19%     
==========================================
  Files          13       13              
  Lines         900      907       +7     
  Branches      270      267       -3     
==========================================
+ Hits          863      868       +5     
- Misses         37       39       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bjohansebas
Copy link
Copy Markdown
Member Author

friendly ping @alexander-akait

filename = path.join(
outputPath,
pathname.slice(publicPathPathname.length),
index || "",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need better logic here, because our logic to search index below, so I think we should split it, i.e. like we have in the send package, if it is ends on / we need to apply this logic, otherwise no, right now we just mix this logic

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We’re already doing it :)

if (pathname && pathname.endsWith("/")) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for using || is to prevent it from being undefined, because it was throwing an error since there’s no index. But if you add "", it behaves the same way and doesn’t add anything.
Image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bjohansebas hm, I always thought that our logic is different here, I will look deeply tomorrow

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not so much in the PR description, there’s a bit about how send implements this functionality.

@alexander-akait
Copy link
Copy Markdown
Member

@bjohansebas in my TODO, I almost finished with the new major release of webpack-cli (release will be tomorrow), the next is webpack-dev-middleware

@alexander-akait alexander-akait force-pushed the next branch 3 times, most recently from 38aed91 to 17b50da Compare March 18, 2026 17:00
Base automatically changed from next to main March 18, 2026 17:47
@alexander-akait
Copy link
Copy Markdown
Member

@bjohansebas Rewritting #2290 to be fully align with sync, maybe in future we will introduce the redirect option wth different values to allow make redirect or return content or 404 if a request is a dir, but let's postpone it, anyway thank you for your PR

@alexander-akait
Copy link
Copy Markdown
Member

Feel free to feedback

@alexander-akait alexander-akait deleted the send-fix branch April 7, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants