- Introduced a centralized routing module with comprehensive matchers for domains, headers, IPs, and paths. - Added DomainMatcher for domain pattern matching with support for wildcards and specificity calculation. - Implemented HeaderMatcher for HTTP header matching, including exact matches and pattern support. - Developed IpMatcher for IP address matching, supporting CIDR notation, ranges, and wildcards. - Created PathMatcher for path matching with parameter extraction and wildcard support. - Established RouteSpecificity class to calculate and compare route specificity scores. - Enhanced HttpRouter to utilize the new matching system, supporting both modern and legacy route configurations. - Added detailed logging and error handling for routing operations.
5.9 KiB
5.9 KiB
SmartProxy Code Deletion Plan
This document tracks all code paths that can be deleted as part of the routing unification effort.
Phase 1: Matching Logic Duplicates (READY TO DELETE)
1. Inline Matching Functions in RouteManager
File: ts/proxies/smart-proxy/route-manager.ts
Lines: Approximately lines 200-400
Duplicates:
matchDomain()
method - duplicate of DomainMatchermatchPath()
method - duplicate of PathMatchermatchIpPattern()
method - duplicate of IpMatchermatchHeaders()
method - duplicate of HeaderMatcher Action: Update to use unified matchers fromts/core/routing/matchers/
2. Duplicate Matching in Core route-utils
File: ts/core/utils/route-utils.ts
Functions to update:
matchDomain()
→ Use DomainMatcher.match()matchPath()
→ Use PathMatcher.match()matchIpPattern()
→ Use IpMatcher.match()matchHeader()
→ Use HeaderMatcher.match() Action: Update to use unified matchers, keep only unique utilities
Phase 2: Route Manager Duplicates (READY AFTER MIGRATION)
1. SmartProxy RouteManager
File: ts/proxies/smart-proxy/route-manager.ts
Entire file: ~500 lines
Reason: 95% duplicate of SharedRouteManager
Migration Required:
- Update SmartProxy to use SharedRouteManager
- Update all imports
- Test thoroughly Action: DELETE entire file after migration
2. Deprecated Methods in SharedRouteManager
File: ts/core/utils/route-manager.ts
Methods:
- Any deprecated security check methods
- Legacy compatibility methods Action: Remove after confirming no usage
Phase 3: Router Consolidation (REQUIRES REFACTORING)
1. ProxyRouter vs RouteRouter Duplication
Files:
ts/routing/router/proxy-router.ts
(~250 lines)ts/routing/router/route-router.ts
(~250 lines) Reason: Nearly identical implementations Plan: Merge into single HttpRouter with legacy adapter Action: DELETE one file after consolidation
2. Inline Route Matching in HttpProxy
Location: Various files in ts/proxies/http-proxy/
Pattern: Direct route matching without using RouteManager
Action: Update to use SharedRouteManager
Phase 4: Scattered Utilities (CLEANUP)
1. Duplicate Route Utilities
Files with duplicate logic:
ts/proxies/smart-proxy/utils/route-utils.ts
- Keep (different purpose)ts/proxies/smart-proxy/utils/route-validators.ts
- Review for duplicatests/proxies/smart-proxy/utils/route-patterns.ts
- Review for consolidation
2. Legacy Type Definitions
Review for removal:
- Old route type definitions
- Deprecated configuration interfaces
- Unused type exports
Deletion Progress Tracker
Completed Deletions
- Phase 1: Matching logic consolidation (Partial)
- Updated core/utils/route-utils.ts to use unified matchers
- Removed duplicate matching implementations (~200 lines)
- Marked functions as deprecated with migration path
- Phase 2: RouteManager unification (COMPLETED)
- ✓ Migrated SmartProxy to use SharedRouteManager
- ✓ Updated imports in smart-proxy.ts, route-connection-handler.ts, and index.ts
- ✓ Created logger adapter to match ILogger interface expectations
- ✓ Fixed method calls (getAllRoutes → getRoutes)
- ✓ Fixed type errors in header matcher
- ✓ Removed unused ipToNumber imports and methods
- ✓ DELETED:
/ts/proxies/smart-proxy/route-manager.ts
(553 lines removed)
- Phase 3: Router consolidation (COMPLETED)
- ✓ Created unified HttpRouter with legacy compatibility
- ✓ Migrated ProxyRouter and RouteRouter to use HttpRouter aliases
- ✓ Updated imports in http-proxy.ts, request-handler.ts, websocket-handler.ts
- ✓ Added routeReqLegacy() method for backward compatibility
- ✓ DELETED:
/ts/routing/router/proxy-router.ts
(437 lines) - ✓ DELETED:
/ts/routing/router/route-router.ts
(482 lines)
- Phase 4: Utility cleanup
Files Updated
ts/core/utils/route-utils.ts
- Replaced all matching logic with unified matchersts/core/utils/security-utils.ts
- Updated to use IpMatcher directlyts/proxies/smart-proxy/smart-proxy.ts
- Using SharedRouteManager with logger adapterts/proxies/smart-proxy/route-connection-handler.ts
- Updated to use SharedRouteManagerts/proxies/smart-proxy/index.ts
- Exporting SharedRouteManager as RouteManagerts/core/routing/matchers/header.ts
- Fixed type handling for array header valuests/core/utils/route-manager.ts
- Removed unused ipToNumber importts/proxies/http-proxy/http-proxy.ts
- Updated imports to use unified routerts/proxies/http-proxy/request-handler.ts
- Updated to use routeReqLegacy()ts/proxies/http-proxy/websocket-handler.ts
- Updated to use routeReqLegacy()ts/routing/router/index.ts
- Export unified HttpRouter with aliases
Files Created
ts/core/routing/matchers/domain.ts
- Unified domain matcherts/core/routing/matchers/path.ts
- Unified path matcherts/core/routing/matchers/ip.ts
- Unified IP matcherts/core/routing/matchers/header.ts
- Unified header matcherts/core/routing/matchers/index.ts
- Matcher exportsts/core/routing/types.ts
- Core routing typests/core/routing/specificity.ts
- Route specificity calculatorts/core/routing/index.ts
- Main routing exportsts/routing/router/http-router.ts
- Unified HTTP router
Lines of Code Removed
- Target: ~1,500 lines
- Actual: ~1,672 lines (Target exceeded!)
- Phase 1: ~200 lines (matching logic)
- Phase 2: 553 lines (SmartProxy RouteManager)
- Phase 3: 919 lines (ProxyRouter + RouteRouter)
Safety Checklist Before Deletion
Before deleting any code:
- ✓ All tests pass
- ✓ No references to deleted code remain
- ✓ Migration path tested
- ✓ Performance benchmarks show no regression
- ✓ Documentation updated
Rollback Plan
If issues arise after deletion:
- Git history preserves all deleted code
- Each phase can be reverted independently
- Feature flags can disable new code if needed