-
-
Notifications
You must be signed in to change notification settings - Fork 455
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
feat(lambda-at-edge): support custom redirects #627
Conversation
import { compileDestination, matchPath } from "./matcher"; | ||
import { RedirectData, RoutesManifest } from "../../types"; | ||
import * as http from "http"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we have Rollup, we can make the component more maintainable by using different files - it will all get bundled/optimized into the handler JS files. Not sure what's a good name, let me know if you have thoughts on this (I put the in routing/
for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think routing/
makes sense. On a related note, would be nice if at some point we refactored all routing concerns into a router
, similar to what the next-server impl does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work 👏
This is the first part of #587. Summary:
path-to-regexp
for custom redirects (same one as Next.js uses). Some of this can also be reused for custom rewrites and headers.next.config.js
. Custom redirects are matched one-by-one from the provided redirects inroutes-manifest
and the first matching redirect is returned. The default trailing slash redirects are ignored for now (by removing them at build time) as they are already handled in a non-regex solution. I also need to put the redirect logic near thedefault-handler
start right after trailing slash redirect, as redirects can overwrite an existing source page (same behavior in Vercel).path-to-regexp
uses RegExp underneath which should be quite performant. I would only expect there to be performance issues if users have really long lists of redirects and/or are using complex paths. For the majority of users, this shouldn't be the case - and the default trailing slash redirects are anyway handled without regex.Note: big PR but a lot of it is updating the tests to have good coverage.
Testing
Added lots of test coverage via unit tests, integration tests, and e2e tests.
Note: there is no e2e test with base path and trailingSlash = true, although I have locally tested it and unit/integration tests should cover it. I will add in a future PR as part of larger work for more e2e tests.
If anyone can pull this branch and test this and/or suggest other test cases I may have missed, that will be really helpful. I think I covered most of them. Thanks!