Added support for allow and block list domains

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
2025-08-23 08:25:43 +01:00
parent 1ac634fd4d
commit b5db132e16

View File

@@ -5,6 +5,11 @@ const url = require('url');
const fs = require('fs').promises; const fs = require('fs').promises;
let PORT = process.env.PORT || 8000; let PORT = process.env.PORT || 8000;
let blockList = (process.env.BLOCKLIST || '').split(',').filter(a => a);
console.log("Blocklist:", blockList);
let allowList = (process.env.ALLOWLIST || '').split(',').filter(a => a);
console.log("AllowList:", allowList);
process.argv.forEach(function (arg) { process.argv.forEach(function (arg) {
if(arg.indexOf('--port=') === 0) { if(arg.indexOf('--port=') === 0) {
PORT = parseInt(arg.replace('--port=', ''), 10); PORT = parseInt(arg.replace('--port=', ''), 10);
@@ -19,6 +24,15 @@ http.createServer((req, response) => {
let remoteURL = url.parse(req.url.substring(1)); let remoteURL = url.parse(req.url.substring(1));
if(!remoteURL.hostname || remoteURL.hostname === 'localhost') return response.end(); if(!remoteURL.hostname || remoteURL.hostname === 'localhost') return response.end();
if(blockList.some(b => remoteURL.hostname == b || remoteURL.hostname.endsWith("." + b))) {
console.log("Domain is in blocklist")
return response.end();
}
if(allowList.length > 0 && !allowList.some(b => remoteURL.hostname == b || remoteURL.hostname.endsWith("." + b))) {
console.log("Domain is not in allowlist")
return response.end();
}
if(req.method === 'OPTIONS') { if(req.method === 'OPTIONS') {
response.writeHead(200, { response.writeHead(200, {
'access-control-allow-origin': req.headers.origin || '*', 'access-control-allow-origin': req.headers.origin || '*',