From d31395412b00dc806f1928310a4eb6dc8d908311 Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Mon, 15 Apr 2019 12:54:29 +0200 Subject: [PATCH] Removed sandbox from apps service no-issue The instansiation of a Module object was only used so that we could override the require method inside external apps, now we have no support for them, we are free to require the internal apps directly. This has no functionality change. --- core/server/services/apps/loader.js | 17 ++++------------- core/server/services/apps/sandbox.js | 13 ------------- 2 files changed, 4 insertions(+), 26 deletions(-) delete mode 100644 core/server/services/apps/sandbox.js diff --git a/core/server/services/apps/loader.js b/core/server/services/apps/loader.js index 1b2294f48d..4cc333be14 100644 --- a/core/server/services/apps/loader.js +++ b/core/server/services/apps/loader.js @@ -1,31 +1,22 @@ const path = require('path'); const _ = require('lodash'); const Promise = require('bluebird'); -const config = require('../../config'); const common = require('../../lib/common'); +const config = require('../../config'); const Proxy = require('./proxy'); -const Sandbox = require('./sandbox'); // Get the full path to an app by name function getAppAbsolutePath(name) { return path.join(config.get('paths').internalAppPath, name); } -// Get a relative path to the given apps root, defaults -// to be relative to __dirname -function getAppRelativePath(name, relativeTo = __dirname) { - const relativePath = path.relative(relativeTo, getAppAbsolutePath(name)); - - if (relativePath.charAt(0) !== '.') { - return './' + relativePath; - } - - return relativePath; +function loadApp(name) { + return require(getAppAbsolutePath(name)); } function getAppByName(name) { // Grab the app class to instantiate - const AppClass = Sandbox.loadApp(getAppRelativePath(name)); + const AppClass = loadApp(name); const proxy = Proxy.getInstance(name); // Check for an actual class, otherwise just use whatever was returned diff --git a/core/server/services/apps/sandbox.js b/core/server/services/apps/sandbox.js deleted file mode 100644 index 1889a52e81..0000000000 --- a/core/server/services/apps/sandbox.js +++ /dev/null @@ -1,13 +0,0 @@ -const Module = require('module'); - -module.exports.loadApp = function loadAppSandboxed(appPath) { - // Resolve the modules path - const resolvedModulePath = Module._resolveFilename(appPath, module.parent); - - // Instantiate a Node Module class - const currentModule = new Module(resolvedModulePath, module.parent); - - currentModule.load(currentModule.id); - - return currentModule.exports; -};