001-drive-proxy-adapter #1
@@ -5,8 +5,9 @@
|
|||||||
* to improve code organization while maintaining vm.Script isolation pattern.
|
* to improve code organization while maintaining vm.Script isolation pattern.
|
||||||
*
|
*
|
||||||
* ARCHITECTURE:
|
* ARCHITECTURE:
|
||||||
* - Loaded by server.js using vm.Script (same as proxy.js)
|
* - This file contains the LITERAL BODY of a function
|
||||||
* - Returns a single object containing all helper functions
|
* - server.js wraps this in a function: (function() { <this code> })()
|
||||||
|
* - Function returns a single object containing all helper functions
|
||||||
* - Injected into globalVariableContext for access by proxy.js
|
* - Injected into globalVariableContext for access by proxy.js
|
||||||
* - NO IMPORTS - All dependencies provided via VM context
|
* - NO IMPORTS - All dependencies provided via VM context
|
||||||
*
|
*
|
||||||
@@ -286,27 +287,27 @@ return { route: null, error: "Not found", statusCode: 404 };
|
|||||||
// Return helpers object with all functions
|
// Return helpers object with all functions
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
({
|
return {
|
||||||
// Error classes
|
// Error classes
|
||||||
DocumentCountExceededError,
|
DocumentCountExceededError,
|
||||||
|
|
||||||
// Utilities
|
// Utilities
|
||||||
generateRequestId,
|
generateRequestId,
|
||||||
validateDocumentId,
|
validateDocumentId,
|
||||||
validateDocumentCount,
|
validateDocumentCount,
|
||||||
|
|
||||||
// XML
|
// XML
|
||||||
escapeXml,
|
escapeXml,
|
||||||
|
|
||||||
// Error mapping
|
// Error mapping
|
||||||
mapDriveErrorToHttp,
|
mapDriveErrorToHttp,
|
||||||
|
|
||||||
// Sitemap
|
// Sitemap
|
||||||
toSitemapEntry,
|
toSitemapEntry,
|
||||||
transformDocumentsToSitemapEntries,
|
transformDocumentsToSitemapEntries,
|
||||||
generateSitemapXML,
|
generateSitemapXML,
|
||||||
generateSitemap,
|
generateSitemap,
|
||||||
|
|
||||||
// Routing
|
// Routing
|
||||||
parseRoute,
|
parseRoute,
|
||||||
});
|
};
|
||||||
|
|||||||
@@ -54,7 +54,10 @@ function loadGlobalVariables() {
|
|||||||
jsFiles.forEach((file) => {
|
jsFiles.forEach((file) => {
|
||||||
const varName = file.replace(".js", "");
|
const varName = file.replace(".js", "");
|
||||||
const code = readFileSync(join(globalDir, file), "utf-8");
|
const code = readFileSync(join(globalDir, file), "utf-8");
|
||||||
const script = new vm.Script(code, { filename: file });
|
|
||||||
|
// Wrap the literal function body in a function and execute
|
||||||
|
const wrappedCode = `(function() {\n${code}\n})()`;
|
||||||
|
const script = new vm.Script(wrappedCode, { filename: file });
|
||||||
const context = vm.createContext({ ...globalVMContext, ...globalVariableContext });
|
const context = vm.createContext({ ...globalVMContext, ...globalVariableContext });
|
||||||
|
|
||||||
// Execute script and capture returned object
|
// Execute script and capture returned object
|
||||||
|
|||||||
Reference in New Issue
Block a user