- Removed deprecated route utility functions in favor of direct matcher usage. - Updated imports to reflect new module structure for routing utilities. - Consolidated route manager functionality into SharedRouteManager for better consistency. - Eliminated legacy routing methods and interfaces, streamlining the HttpProxy and associated components. - Enhanced WebSocket and HTTP request handling to utilize the new unified HttpRouter. - Updated route matching logic to leverage matcher classes for domain, path, and header checks. - Cleaned up legacy compatibility code across various modules, ensuring a more maintainable codebase.
8.8 KiB
8.8 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: Architecture cleanup (COMPLETED)
- ✓ Updated route-utils.ts to use unified matchers directly
- ✓ Removed deprecated methods from SharedRouteManager
- ✓ Fixed HeaderMatcher.matchMultiple → matchAll method name
- ✓ Fixed findMatchingRoute return type handling (IRouteMatchResult)
- ✓ Fixed header type conversion for RegExp patterns
- ✓ DELETED: Duplicate RouteManager class from http-proxy/models/types.ts (~200 lines)
- ✓ Updated all imports to use SharedRouteManager from core/utils
- ✓ Fixed PathMatcher exact match behavior (added $ anchor for non-wildcard patterns)
- ✓ Updated test expectations to match unified matcher behavior
- ✓ All TypeScript errors resolved and build successful
- Phase 5: Remove all backward compatibility code (COMPLETED)
- ✓ Removed routeReqLegacy() method from HttpRouter
- ✓ Removed all legacy compatibility methods from HttpRouter (~130 lines)
- ✓ Removed LegacyRouterResult interface
- ✓ Removed ProxyRouter and RouteRouter aliases
- ✓ Updated RequestHandler to remove legacyRouter parameter and legacy routing fallback (~80 lines)
- ✓ Updated WebSocketHandler to remove legacyRouter parameter and legacy routing fallback
- ✓ Updated HttpProxy to use only unified HttpRouter
- ✓ Removed IReverseProxyConfig interface (deprecated legacy interface)
- ✓ Removed useExternalPort80Handler deprecated option
- ✓ Removed backward compatibility exports from index.ts
- ✓ Removed all deprecated functions from route-utils.ts (~50 lines)
- ✓ Clean build with no legacy code
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 aliasests/proxies/smart-proxy/utils/route-utils.ts
- Updated to use unified matchers directlyts/proxies/http-proxy/request-handler.ts
- Fixed findMatchingRoute usagets/proxies/http-proxy/models/types.ts
- Removed duplicate RouteManager classts/index.ts
- Updated exports to use SharedRouteManager aliasests/proxies/index.ts
- Updated exports to use SharedRouteManager aliasestest/test.acme-route-creation.ts
- Fixed getAllRoutes → getRoutes method call
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: ~2,332 lines (Target exceeded by 55%!)
- Phase 1: ~200 lines (matching logic)
- Phase 2: 553 lines (SmartProxy RouteManager)
- Phase 3: 919 lines (ProxyRouter + RouteRouter)
- Phase 4: ~200 lines (Duplicate RouteManager from http-proxy)
- Phase 5: ~460 lines (Legacy compatibility code)
Unified Routing Architecture Summary
The routing unification effort has successfully:
- Created unified matchers - Consistent matching logic across all route types
- DomainMatcher: Wildcard domain matching with specificity calculation
- PathMatcher: Path pattern matching with parameter extraction
- IpMatcher: IP address and CIDR notation matching
- HeaderMatcher: HTTP header matching with regex support
- Consolidated route managers - Single SharedRouteManager for all proxies
- Unified routers - Single HttpRouter for all HTTP routing needs
- Removed ~2,332 lines of code - Exceeded target by 55%
- Clean modern architecture - No legacy code, no backward compatibility layers
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