feat: Redirect rules (wildcard/pattern matching links)#3400
Draft
Suhaib3100 wants to merge 1 commit intodubinc:mainfrom
Draft
feat: Redirect rules (wildcard/pattern matching links)#3400Suhaib3100 wants to merge 1 commit intodubinc:mainfrom
Suhaib3100 wants to merge 1 commit intodubinc:mainfrom
Conversation
Contributor
|
@Suhaib3100 is attempting to deploy a commit to the Dub Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This adds support for redirect rules that use pattern matching to redirect multiple URLs to a single destination. Closes dubinc#529. Changes: - Add isRule and rulePattern fields to Link schema - Create rule-cache.ts for caching rules per domain - Add match-rule.ts with pattern matching logic (wildcards, named params) - Update middleware to fallback to rule matching when exact link not found - Pass aliasLinkId to recordClick for analytics tracking - Add validation in processLink for rule patterns - Update Zod schemas and TypeScript types Pattern syntax: - Wildcards: /blog/* matches /blog/anything - Named params: /docs/:slug matches /docs/intro (captures slug) - Specificity-based matching (more specific patterns match first)
cfd57b5 to
6831abd
Compare
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.
Summary
Implements redirect rules (#529) - a highly requested feature that allows pattern-based URL matching for short links.
What it does
Instead of creating individual short links for every URL, users can now create a single redirect rule like:
/blog/*→ redirects any/blog/hello-world,/blog/2024/post, etc./docs/:slug→ redirects/docs/intro,/docs/apiwith captured paramsChanges
Schema:
isRule(boolean) andrulePattern(string) fields to Link model[domain, isRule]for efficient rule lookupMiddleware:
Analytics:
alias_link_idfield in Tinybird to track matched pathsAPI:
isRule: truePOST /api/linkswithisRule+rulePattern)Pattern syntax
Testing needed
Closes #529
Happy to adjust anything based on feedback!