Created
April 22, 2020 15:41
-
-
Save scripting/22aabb93041a4b04e1ac69bc1ebb36aa to your computer and use it in GitHub Desktop.
Chuck this is how I run filter scripts. I probably will convert to requireFromString.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function runFilterScript (host, callback) { //3/23/20 by DW | |
var f = getFullFilePath (domainsPath) + host + filterFname; | |
fs.readFile (f, function (err, data) { | |
if (err) { | |
callback (false); //file doesn't exist -- we didn't run the filter script | |
} | |
else { | |
try { | |
const options = { | |
httpRequest, | |
serveLocalFile: function (f) { | |
console.log ("serveLocalFile (" + f + ")"); | |
serveFile (f, config); | |
} | |
}; | |
const filterfile = __dirname + "/" + f; | |
if (require.cache [filterfile] !== undefined) { | |
delete require.cache [filterfile]; | |
} | |
require (filterfile).filter (options, function (err, httpResponse) { | |
if (err) { | |
httpRespond (500, "text/plain", err.message); | |
callback (true); //we handled it | |
} | |
else { | |
if (httpResponse.flNotHandled) { //the plugin doesn't want this, let other functions in pagePark have a try | |
callback (false); | |
} | |
else { | |
httpRespond (httpResponse.code, httpResponse.type, httpResponse.val); | |
callback (true); //we handled it | |
} | |
} | |
}); | |
} | |
catch (err) { | |
httpRespond (500, "text/plain", err.message); | |
callback (true); //we handled it | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment