'Cannot execute context.route in for loop
I'm using route.abort() to block some URLs.
When I'm using code like this:
await this.context.route(/a.net/, route => route.abort());
works as expected.
BUT since I have a lot of routes to block instead of writing multiple lines of code above I wanted to create config with routes to block and execute await in for loop.
My config.ts like:
export const config = {
use: {
some_list: '/a.net/,/b.net/,/c.net/'
},
};
rest of the code to block all routes from list:
let listOfResources = config.use.some_list.split(',')
for (let value of listOfResources) {
await this.context.route(value, route => route.abort());
}
but in the above For loop the aborting or routes is not happening, could anyone help me with that?
Solution 1:[1]
let endpoints = ['/a.net', '/b.net', '/c.net']
endpoints.forEach((path) => {
this.context.route(path, route => route.abort());
});
I'm not very familiar with route.abort() function but maybe this could help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pedro Barreto |
