tangled
alpha
login
or
join now
dunkirk.sh
/
control
0
fork
atom
a control panel for my server
0
fork
atom
overview
issues
pulls
pipelines
feat: add wildcards
dunkirk.sh
2 months ago
f9f45e8f
e431de6f
verified
This commit was signed with the committer's
known signature
.
dunkirk.sh
SSH Key Fingerprint:
SHA256:DqcG0RXYExE26KiWo3VxJnsxswN1QNfTBvB+bdSpk80=
+17
-2
1 changed file
expand all
collapse all
unified
split
src
flags.ts
+17
-2
src/flags.ts
···
121
121
return result;
122
122
}
123
123
124
124
+
// Match a path pattern against a request path (supports * wildcard for single segment)
125
125
+
function matchPath(pattern: string, path: string): boolean {
126
126
+
if (!pattern.includes("*")) {
127
127
+
return path === pattern || path.startsWith(pattern + "/") || path.startsWith(pattern + "?");
128
128
+
}
129
129
+
130
130
+
// Convert pattern to regex: * matches any single path segment
131
131
+
const regexPattern = pattern
132
132
+
.replace(/[.+^${}()|[\]\\]/g, "\\$&") // escape regex special chars except *
133
133
+
.replace(/\*/g, "[^/]+"); // * matches one path segment
134
134
+
135
135
+
const regex = new RegExp(`^${regexPattern}($|\\?|/)`);
136
136
+
return regex.test(path);
137
137
+
}
138
138
+
124
139
// Check if a request should be blocked based on host and path
125
140
export function shouldBlock(host: string, path: string): boolean {
126
141
const config = getConfig();
···
137
152
continue;
138
153
}
139
154
140
140
-
// Check if any of the flag's paths match
155
155
+
// Check if any of the flag's paths match (supports * wildcard)
141
156
for (const flagPath of flag.paths) {
142
142
-
if (path === flagPath || path.startsWith(flagPath + "/") || path.startsWith(flagPath + "?")) {
157
157
+
if (matchPath(flagPath, path)) {
143
158
return true;
144
159
}
145
160
}