Skip to content

Commit

Permalink
allow regex in blocklist
Browse files Browse the repository at this point in the history
  • Loading branch information
s-tn committed Aug 17, 2023
1 parent 903386c commit 27de615
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions lib/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ import about from '../global/util/about';

if (request.url.startsWith(__dynamic.config.bare.path.toString())) return false;
if (request.url.startsWith(location.origin + self.__dynamic$config.prefix)) return true;
if (blockList.includes(request.url)) return false;

if (request.mode !== 'navigate') request.client = (await self.clients.matchAll()).find((e:any)=>e.id==event.clientId);

Expand Down Expand Up @@ -221,7 +220,7 @@ import about from '../global/util/about';

Dynamic.meta.load(new URL(Dynamic.url.decode(new URL(request.url))));

if (blockList.indexOf(Dynamic.meta.host) !== -1) return (this.fire('blocked', [Dynamic.meta, request]) || new Response(null, {
if (blockList.indexOf(Dynamic.meta.host) !== -1 || blockList.find((entry: RegExp) => entry instanceof RegExp && entry.test(Dynamic.meta.host))) return (this.fire('blocked', [Dynamic.meta, request]) || new Response(null, {
status: 403,
statusText: 'Forbidden'
}));
Expand Down

0 comments on commit 27de615

Please sign in to comment.