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:
@@ -5,18 +5,11 @@
|
||||
* and additional route-specific utilities.
|
||||
*/
|
||||
|
||||
import { DomainMatcher, PathMatcher, IpMatcher, HeaderMatcher } from '../routing/matchers/index.js';
|
||||
import { RouteSpecificity } from '../routing/specificity.js';
|
||||
import type { IRouteSpecificity } from '../routing/types.js';
|
||||
import { DomainMatcher, PathMatcher, IpMatcher, HeaderMatcher } from './matchers/index.js';
|
||||
import { RouteSpecificity } from './specificity.js';
|
||||
import type { IRouteSpecificity } from './types.js';
|
||||
import type { IRouteConfig } from '../../proxies/smart-proxy/models/route-types.js';
|
||||
|
||||
/**
|
||||
* Match a domain pattern against a domain
|
||||
* @deprecated Use DomainMatcher.match() directly
|
||||
*/
|
||||
export function matchDomain(pattern: string, domain: string): boolean {
|
||||
return DomainMatcher.match(pattern, domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Match domains from a route against a given domain
|
||||
@@ -37,56 +30,10 @@ export function matchRouteDomain(domains: string | string[] | undefined, domain:
|
||||
}
|
||||
|
||||
const patterns = Array.isArray(domains) ? domains : [domains];
|
||||
return patterns.some(pattern => matchDomain(pattern, domain));
|
||||
return patterns.some(pattern => DomainMatcher.match(pattern, domain));
|
||||
}
|
||||
|
||||
/**
|
||||
* Match a path pattern against a path
|
||||
* @deprecated Use PathMatcher.match() directly
|
||||
*/
|
||||
export function matchPath(pattern: string, path: string): boolean {
|
||||
return PathMatcher.match(pattern, path).matches;
|
||||
}
|
||||
|
||||
// Helper functions removed - use IpMatcher internal methods instead
|
||||
|
||||
/**
|
||||
* Match an IP against a CIDR pattern
|
||||
* @deprecated Use IpMatcher.matchCidr() directly
|
||||
*/
|
||||
export function matchIpCidr(cidr: string, ip: string): boolean {
|
||||
return IpMatcher.matchCidr(cidr, ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Match an IP pattern against an IP
|
||||
* @deprecated Use IpMatcher.match() directly
|
||||
*/
|
||||
export function matchIpPattern(pattern: string, ip: string): boolean {
|
||||
return IpMatcher.match(pattern, ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Match an IP against allowed and blocked IP patterns
|
||||
* @deprecated Use IpMatcher.isAuthorized() directly
|
||||
*/
|
||||
export function isIpAuthorized(
|
||||
ip: string,
|
||||
ipAllowList: string[] = ['*'],
|
||||
ipBlockList: string[] = []
|
||||
): boolean {
|
||||
return IpMatcher.isAuthorized(ip, ipAllowList, ipBlockList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Match an HTTP header pattern against a header value
|
||||
* @deprecated Use HeaderMatcher.match() directly
|
||||
*/
|
||||
export function matchHeader(pattern: string | RegExp, value: string): boolean {
|
||||
// Convert RegExp to string pattern for HeaderMatcher
|
||||
const stringPattern = pattern instanceof RegExp ? pattern.source : pattern;
|
||||
return HeaderMatcher.match(stringPattern, value, { exactMatch: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate route specificity score
|
||||
@@ -94,7 +41,6 @@ export function matchHeader(pattern: string | RegExp, value: string): boolean {
|
||||
*
|
||||
* @param match Match criteria to evaluate
|
||||
* @returns Numeric specificity score
|
||||
* @deprecated Consider using RouteSpecificity.calculate() with full IRouteConfig
|
||||
*/
|
||||
export function calculateRouteSpecificity(match: {
|
||||
domains?: string | string[];
|
||||
|
Reference in New Issue
Block a user