001-drive-proxy-adapter #1

Merged
Peter.Morton merged 25 commits from 001-drive-proxy-adapter into main 2026-03-07 12:45:57 -06:00
Showing only changes of commit d6fa0b1f97 - Show all commits

View File

@@ -69,10 +69,8 @@ function loadGlobalObjects() {
}
/**
* Load helpers module using vm.Script
* Load helpers module using vm.Script and store in globalVariableContext
* Pattern: helpers.js returns object with utility functions via IIFE
*
* @returns {Object} Helpers object with all utility functions
*/
function loadHelpers() {
const helpersPath = join(__dirname, "globalVariables", "helpers.js");
@@ -81,21 +79,21 @@ function loadHelpers() {
const helpersCode = readFileSync(helpersPath, "utf-8");
const helpersScript = new vm.Script(helpersCode, { filename: "helpers.js" });
// Create isolated context for helpers (needs crypto and console)
const helpersContext = vm.createContext({
// Execute helpers.js in context with crypto and console
// Returns object with all helper functions
const tempContext = vm.createContext({
crypto,
console: logger,
});
const helpers = helpersScript.runInContext(tempContext);
// Execute helpers.js and get the returned object
const helpers = helpersScript.runInContext(helpersContext);
// Store in globalVariableContext to be spread into per-request context
globalVariableContext.helpers = helpers;
logger.info("Loaded helpers module", {
functions: Object.keys(helpers).length,
exports: Object.keys(helpers),
});
return helpers;
} catch (error) {
logger.error("Failed to load helpers module", {
path: helpersPath,
@@ -160,8 +158,8 @@ async function startServer() {
// Load global objects from globalVariables/ directory (e.g., service account keys)
loadGlobalObjects();
// Load helpers module via vm.Script
const helpers = loadHelpers();
// Load helpers module via vm.Script and add to globalVariableContext
loadHelpers();
logger.info("Starting Proxy Script Server...");
logger.info(
@@ -184,10 +182,10 @@ async function startServer() {
const server = http.createServer((req, res) => {
try {
// Create a context with all globals that proxy.js needs
// globalVariableContext includes both JSON data and helpers object
const context = vm.createContext({
...globalVMContext,
...globalVariableContext,
helpers,
req,
res,
});