From 9969a6e4f2d3efdddd9ca3467957ce2338109966 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Mon, 19 Jan 2015 16:50:01 +0100 Subject: [PATCH] Fixed some conflicts in foxx routing. --- .../modules/org/arangodb/foxx/manager.js | 45 ++++++++++++------- .../modules/org/arangodb/foxx/routing.js | 5 +-- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/js/server/modules/org/arangodb/foxx/manager.js b/js/server/modules/org/arangodb/foxx/manager.js index ff88cd244e..7a3c4fb580 100644 --- a/js/server/modules/org/arangodb/foxx/manager.js +++ b/js/server/modules/org/arangodb/foxx/manager.js @@ -1211,6 +1211,7 @@ exports.initializeFoxx = function () { var checkParameter = arangodb.checkParameter; var errors = arangodb.errors; var download = require("internal").download; + var executeGlobalContextFunction = require("internal").executeGlobalContextFunction; var throwDownloadError = arangodb.throwDownloadError; var throwFileNotFound = arangodb.throwFileNotFound; @@ -1225,6 +1226,26 @@ exports.initializeFoxx = function () { // --SECTION-- private functions // ----------------------------------------------------------------------------- + var refillCaches = function(computeRoutes) { + appCache = {}; + var cursor = utils.tmp_getStorage().all(); + var config, app, route; + var routes = []; + + while (cursor.hasNext()) { + config = cursor.next(); + app = new ArangoApp(config); + appCache[app._mount] = app; + if (computeRoutes) { + route = routeApp(app); + if (route) { + routes.push(route); + } + } + } + return routes; + }; + //////////////////////////////////////////////////////////////////////////////// /// @brief lookup app in cache /// Returns either the app or undefined if it is not cached. @@ -1684,9 +1705,6 @@ exports.initializeFoxx = function () { delete appCache[mount]; var app = createApp(mount, options); utils.tmp_getStorage().save(app.toJSON()); - var routes = routeApp(app); - require("console").log("Routes", Object.keys(routes)); - // TODO Routing weiter? }; @@ -1736,6 +1754,7 @@ exports.initializeFoxx = function () { [ "Mount path", "string" ] ], [ appInfo, mount ] ); _install(appInfo, mount, options, true); + executeGlobalContextFunction("reloadRouting"); }; //////////////////////////////////////////////////////////////////////////////// @@ -1766,6 +1785,7 @@ exports.initializeFoxx = function () { [ [ "Mount path", "string" ] ], [ mount ] ); _uninstall(mount); + executeGlobalContextFunction("reloadRouting"); }; //////////////////////////////////////////////////////////////////////////////// @@ -1781,6 +1801,7 @@ exports.initializeFoxx = function () { [ appInfo, mount ] ); _uninstall(mount, true); _install(appInfo, mount, options, true); + executeGlobalContextFunction("reloadRouting"); }; //////////////////////////////////////////////////////////////////////////////// @@ -1796,6 +1817,7 @@ exports.initializeFoxx = function () { [ appInfo, mount ] ); _uninstall(mount, false); _install(appInfo, mount, options, false); + executeGlobalContextFunction("reloadRouting"); }; //////////////////////////////////////////////////////////////////////////////// @@ -1803,20 +1825,12 @@ exports.initializeFoxx = function () { //////////////////////////////////////////////////////////////////////////////// var initializeFoxx = function() { - appCache = {}; - var cursor = utils.tmp_getStorage().all(); - var config, app; - - while (cursor.hasNext()) { - config = cursor.next(); - app = new ArangoApp(config); - appCache[app._mount] = app; - var routes = routeApp(app); - require("console").log("Routes", Object.keys(routes)); - // TODO Routing weiter? - } + return refillCaches(false); }; + var appRoutes = function() { + return refillCaches(true); + }; // ----------------------------------------------------------------------------- // --SECTION-- exports // ----------------------------------------------------------------------------- @@ -1832,6 +1846,7 @@ exports.initializeFoxx = function () { exports.uninstall = uninstall; exports.replace = replace; exports.upgrade = upgrade; + exports.appRoutes = appRoutes; //////////////////////////////////////////////////////////////////////////////// /// @brief Exports from foxx utils module. diff --git a/js/server/modules/org/arangodb/foxx/routing.js b/js/server/modules/org/arangodb/foxx/routing.js index f3a17c205d..1b4f3ab5a3 100644 --- a/js/server/modules/org/arangodb/foxx/routing.js +++ b/js/server/modules/org/arangodb/foxx/routing.js @@ -312,7 +312,7 @@ appContext: { app: app, - module: app._module // TODO + module: app._context.appModule } }; @@ -422,8 +422,7 @@ // install all files and assets installAssets(app, routes); - setFoxxRouting(app._mount, routes); - // and return all routes + // Trigger the setFoxxRouting in actions return routes; } catch (err) {