feat(routing): Implement unified routing and matching system

- 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.
This commit is contained in:
2025-06-02 03:57:52 +00:00
parent 01e1153fb8
commit 54ffbadb86
28 changed files with 1827 additions and 1724 deletions

View File

@ -1,12 +1,19 @@
/**
* HTTP routing
* HTTP routing - Unified HttpRouter with backward compatibility
*/
// Export selectively to avoid ambiguity between duplicate type names
export { ProxyRouter } from './proxy-router.js';
export type { IPathPatternConfig } from './proxy-router.js';
// Re-export the RouterResult and PathPatternConfig from proxy-router.js (legacy names maintained for compatibility)
export type { PathPatternConfig as ProxyPathPatternConfig, RouterResult as ProxyRouterResult } from './proxy-router.js';
// Export the unified HttpRouter with backward compatibility aliases
export { HttpRouter, ProxyRouter, RouteRouter } from './http-router.js';
export type { RouterResult, LegacyRouterResult, ILogger } from './http-router.js';
export { RouteRouter } from './route-router.js';
export type { PathPatternConfig as RoutePathPatternConfig, RouterResult as RouteRouterResult } from './route-router.js';
// Legacy type exports for backward compatibility
export type { RouterResult as ProxyRouterResult } from './http-router.js';
export type { RouterResult as RouteRouterResult } from './http-router.js';
// Path pattern config is no longer needed as it's part of IRouteConfig.match.path
export interface IPathPatternConfig {
pathPattern?: string;
}
export type { IPathPatternConfig as PathPatternConfig };
export type { IPathPatternConfig as ProxyPathPatternConfig };
export type { IPathPatternConfig as RoutePathPatternConfig };