From c70c43c02b9b7d54a926425b3869c068d6fb243f Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Mon, 19 Jan 2015 17:37:43 +0100 Subject: [PATCH] Mount all system apps on startup --- .../modules/org/arangodb/foxx/manager.js | 47 +++++++++++++++++-- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/js/server/modules/org/arangodb/foxx/manager.js b/js/server/modules/org/arangodb/foxx/manager.js index ce80fb3c46..dc737ad1fe 100644 --- a/js/server/modules/org/arangodb/foxx/manager.js +++ b/js/server/modules/org/arangodb/foxx/manager.js @@ -61,6 +61,13 @@ // ----------------------------------------------------------------------------- var appCache = {}; + var usedSystemMountPoints = [ + "/_admin/aardvark", // Admin interface. + "/_system/cerberus", // Password recovery. + "/_api/gharial", // General_Graph API. + "/_system/sessions", // Sessions. + "/_system/simple-auth" // Authentication. + ]; // ----------------------------------------------------------------------------- // --SECTION-- private functions @@ -86,6 +93,21 @@ return routes; }; + //////////////////////////////////////////////////////////////////////////////// + /// @brief Makes sure all system apps are mounted. + //////////////////////////////////////////////////////////////////////////////// + var checkMountedSystemApps = function() { + var i, mount; + for (i = 0; i < usedSystemMountPoints.length; ++i) { + mount = usedSystemMountPoints[i]; + if (!appCache[mount]) { + // System app not written to collection + _scanFoxx(mount, {}); + setup(mount); + } + } + }; + //////////////////////////////////////////////////////////////////////////////// /// @brief lookup app in cache /// Returns either the app or undefined if it is not cached. @@ -536,15 +558,29 @@ } }; + //////////////////////////////////////////////////////////////////////////////// + /// @brief Internal scanFoxx function. Check scanFoxx. + /// Does not check parameters and throws errors. + //////////////////////////////////////////////////////////////////////////////// + + var _scanFoxx = function(mount, options) { + delete appCache[mount]; + var app = createApp(mount, options); + utils.tmp_getStorage().save(app.toJSON()); + }; + //////////////////////////////////////////////////////////////////////////////// /// @brief Scans the sources of the given mountpoint and publishes the routes /// /// TODO: Long Documentation! //////////////////////////////////////////////////////////////////////////////// var scanFoxx = function(mount, options) { - delete appCache[mount]; - var app = createApp(mount, options); - utils.tmp_getStorage().save(app.toJSON()); + checkParameter( + "mount()", + [ [ "Mount path", "string" ] ], + [ mount ] ); + _scanFoxx(mount, options); + executeGlobalContextFunction("reloadRouting"); }; @@ -576,7 +612,7 @@ // try appstore throw "Not implemented yet"; } - scanFoxx(mount, options); + _scanFoxx(mount, options); if (runSetup) { setup(mount); } @@ -665,7 +701,8 @@ //////////////////////////////////////////////////////////////////////////////// var initializeFoxx = function() { - return refillCaches(false); + refillCaches(false); + checkMountedSystemApps(); }; var appRoutes = function() {