Refactor routing and proxy components for improved structure and compatibility
- 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.
This commit is contained in:
@ -93,7 +93,30 @@ This document tracks all code paths that can be deleted as part of the routing u
|
||||
- ✓ 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
|
||||
- [x] 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
|
||||
- [x] 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
|
||||
1. `ts/core/utils/route-utils.ts` - Replaced all matching logic with unified matchers
|
||||
@ -107,6 +130,12 @@ This document tracks all code paths that can be deleted as part of the routing u
|
||||
9. `ts/proxies/http-proxy/request-handler.ts` - Updated to use routeReqLegacy()
|
||||
10. `ts/proxies/http-proxy/websocket-handler.ts` - Updated to use routeReqLegacy()
|
||||
11. `ts/routing/router/index.ts` - Export unified HttpRouter with aliases
|
||||
12. `ts/proxies/smart-proxy/utils/route-utils.ts` - Updated to use unified matchers directly
|
||||
13. `ts/proxies/http-proxy/request-handler.ts` - Fixed findMatchingRoute usage
|
||||
14. `ts/proxies/http-proxy/models/types.ts` - Removed duplicate RouteManager class
|
||||
15. `ts/index.ts` - Updated exports to use SharedRouteManager aliases
|
||||
16. `ts/proxies/index.ts` - Updated exports to use SharedRouteManager aliases
|
||||
17. `test/test.acme-route-creation.ts` - Fixed getAllRoutes → getRoutes method call
|
||||
|
||||
### Files Created
|
||||
1. `ts/core/routing/matchers/domain.ts` - Unified domain matcher
|
||||
@ -121,10 +150,25 @@ This document tracks all code paths that can be deleted as part of the routing u
|
||||
|
||||
### Lines of Code Removed
|
||||
- Target: ~1,500 lines
|
||||
- Actual: ~1,672 lines (Target exceeded!)
|
||||
- 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:
|
||||
1. **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
|
||||
2. **Consolidated route managers** - Single SharedRouteManager for all proxies
|
||||
3. **Unified routers** - Single HttpRouter for all HTTP routing needs
|
||||
4. **Removed ~2,332 lines of code** - Exceeded target by 55%
|
||||
5. **Clean modern architecture** - No legacy code, no backward compatibility layers
|
||||
|
||||
## Safety Checklist Before Deletion
|
||||
|
||||
|
Reference in New Issue
Block a user