-
Notifications
You must be signed in to change notification settings - Fork 56
Recipe: routing certain domains through a proxy
Vladislav Yarmak edited this page Dec 7, 2025
·
4 revisions
Domains (and their subdomains) listed in file domains.txt will be redirected into a proxy http://192.168.88.1:8001, all other connections go directly.
Run dumbproxy like this:
dumbproxy -js-proxy-router routeDomains.js
routeDomains.js:
function normalizeDomain(d) {
return d.replace(/\.$/, "").toLowerCase();
}
const domains = new Set();
readFile("domains.txt")
.split(/\r?\n|\r|\n/g)
.forEach(line => {
line = line.replace(/#.*$/, "").trim(); // strip comment part and whitespace
line = normalizeDomain(line); // normalize domain name
if (line !== "") {
domains.add(line);
}
});
//print("loaded domains:");
//print(JSON.stringify(Array.from(domains)));
function getProxy(req, dst, username) {
let host = normalizeDomain(dst.originalHost);
do {
if (domains.has(host)) return "http://192.168.88.1:8001"; // proxy
host = host.replace(/^[^\.]*.|[^\.]*$/, "");
} while (host);
return ""; // bypass
}