a control panel for my server

feat: add wildcards

dunkirk.sh f9f45e8f e431de6f

verified
+17 -2
+17 -2
src/flags.ts
··· 121 return result; 122 } 123 124 // Check if a request should be blocked based on host and path 125 export function shouldBlock(host: string, path: string): boolean { 126 const config = getConfig(); ··· 137 continue; 138 } 139 140 - // Check if any of the flag's paths match 141 for (const flagPath of flag.paths) { 142 - if (path === flagPath || path.startsWith(flagPath + "/") || path.startsWith(flagPath + "?")) { 143 return true; 144 } 145 }
··· 121 return result; 122 } 123 124 + // Match a path pattern against a request path (supports * wildcard for single segment) 125 + function matchPath(pattern: string, path: string): boolean { 126 + if (!pattern.includes("*")) { 127 + return path === pattern || path.startsWith(pattern + "/") || path.startsWith(pattern + "?"); 128 + } 129 + 130 + // Convert pattern to regex: * matches any single path segment 131 + const regexPattern = pattern 132 + .replace(/[.+^${}()|[\]\\]/g, "\\$&") // escape regex special chars except * 133 + .replace(/\*/g, "[^/]+"); // * matches one path segment 134 + 135 + const regex = new RegExp(`^${regexPattern}($|\\?|/)`); 136 + return regex.test(path); 137 + } 138 + 139 // Check if a request should be blocked based on host and path 140 export function shouldBlock(host: string, path: string): boolean { 141 const config = getConfig(); ··· 152 continue; 153 } 154 155 + // Check if any of the flag's paths match (supports * wildcard) 156 for (const flagPath of flag.paths) { 157 + if (matchPath(flagPath, path)) { 158 return true; 159 } 160 }