Repository navigation
refactor(middleware): convert redirects middleware and tests to TypeScript - #616
Merged
Merged
Conversation
bkendall
force-pushed
the
convert_middleware_redirects
branch
from
November 2, 2026 23:35
ceabd30 to
5106350
Compare
There was a problem hiding this comment.
Code Review
This pull request migrates the redirects middleware and its unit tests from JavaScript to TypeScript, refactoring the redirect logic into a structured Redirect class and updating tests to use modern async/await syntax. The review feedback suggests several key improvements: caching compiled Redirect instances with a WeakMap to boost performance, wrapping decodeURI in a try-catch block to prevent crashes on malformed URLs, passing configuration errors to next() instead of throwing them directly, and using indexOf and slice to parse query strings more robustly.
bkendall
force-pushed
the
convert_middleware_redirects
branch
2 times, most recently
from
November 2, 2026 23:46
6d434df to
dd43c70
Compare
joehan
reviewed
Nov 4, 2026
joehan
left a comment
Member
There was a problem hiding this comment.
Code Review: PR #616 (refactor(middleware): convert redirects middleware and tests to TypeScript)
Strengths & LGTM Aspects
- Clean extraction of redirect config caching and pattern matching.
- Strong test suite covering status codes and redirect targets.
Key Findings to Address
return next(new Error(...))fails open insidesuperstatic: Insrc/activator.js,_run()takes zero arguments. Passing an error tonext(err)pops the next middleware instead of terminating the request, silently serving static files200 OKon malformed redirect configs.decodeURI(req.url)before?lets?%bypass all redirects: Decoding the fullreq.urlbefore splitting the query string catchesURIErroron requests likeGET /source?discount=50%, callsnext(), and bypasses all redirect rules to servesource.htmlwith200 OK.encodeURI(addQuery(dest, qs))double-encodes query parameters: Reserved query escapes like%26or%3Ain the query string get double-encoded to%2526.- 0-argument factory function:
export = function ()accepts 0 arguments, failingTS2554when called asredirects(spec)byactivator.js.
Converts src/utils/patterns.js to TypeScript with typed pattern matching utilities and adds unit tests in test/unit/utils/patterns.spec.ts.
bkendall
force-pushed
the
convert_utils_patterns
branch
from
November 4, 2026 21:51
b93843e to
9b1084a
Compare
…cript Converts src/middleware/redirects.js and test/unit/middleware/redirects.spec.js to TypeScript (src/middleware/redirects.ts and test/unit/middleware/redirects.spec.ts). - Reuses Redirect and Configuration types from src/config.ts and patterns.configMatcher / patterns.createRaw from src/utils/patterns.ts. - Replaces internal Redirect constructor function with a typed class/interface while preserving exact path-to-regexp capture, query string preservation, and CommonJS factory export compatibility.
bkendall
force-pushed
the
convert_middleware_redirects
branch
from
November 4, 2026 21:55
dd43c70 to
0f187e2
Compare
Base automatically changed from
convert_utils_patterns
to
prioritize_js_to_ts
November 7, 2026 00:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Converts
src/middleware/redirects.jsandtest/unit/middleware/redirects.spec.jsto TypeScript (src/middleware/redirects.tsandtest/unit/middleware/redirects.spec.ts).RedirectandConfigurationtypes andpatterns.configMatcher/patterns.createRawfromsrc/utils/patterns.ts.Redirectconstructor function with a typed class/interface while preserving exact path-to-regexp capture, query string preservation, and CommonJS factory export compatibility forsrc/superstatic.js.