diff --git a/js/server/modules/org/arangodb/foxx.js b/js/server/modules/org/arangodb/foxx.js index 4545f3bc93..1f4870d60b 100644 --- a/js/server/modules/org/arangodb/foxx.js +++ b/js/server/modules/org/arangodb/foxx.js @@ -44,7 +44,7 @@ exports.createQuery = createQuery; exports.toJSONSchema = toJSONSchema; exports.requireApp = function (path) { 'use strict'; - return manager.mountedApp(arangodb.normalizeURL('/' + path)); + return manager.requireApp(arangodb.normalizeURL('/' + path)); }; // ----------------------------------------------------------------------------- diff --git a/js/server/modules/org/arangodb/foxx/arangoApp.js b/js/server/modules/org/arangodb/foxx/arangoApp.js index 242b15d8eb..4508a64cfd 100644 --- a/js/server/modules/org/arangodb/foxx/arangoApp.js +++ b/js/server/modules/org/arangodb/foxx/arangoApp.js @@ -47,6 +47,25 @@ var errors = arangodb.errors; var throwFileNotFound = arangodb.throwFileNotFound; + +// ----------------------------------------------------------------------------- +// --SECTION-- private functions +// ----------------------------------------------------------------------------- + + var applyDefaultConfig = function(config) { + if (config === undefined) { + return {}; + } + var res = {}; + var attr; + for (attr in config) { + if (config.hasOwnProperty(attr) && config[attr].hasOwnProperty("default")) { + res[attr] = config[attr].default; + } + } + return res; + }; + // ----------------------------------------------------------------------------- // --SECTION-- constructors and destructors // ----------------------------------------------------------------------------- @@ -137,6 +156,11 @@ this._isDevelopment = config.isDevelopment || false; this._exports = {}; this._collectionPrefix = this._mount.substr(1).replace(/-/g, "_").replace(/\//g, "_") + "_"; + // Apply the default configuration and ignore all missing options + + var cfg = config.options.configuration; + this._options.configuration = applyDefaultConfig(this._manifest.configuration); + this.configure(cfg); this._context = new AppContext(this); if (! this._manifest.hasOwnProperty("defaultDocument")) { diff --git a/js/server/modules/org/arangodb/foxx/manager.js b/js/server/modules/org/arangodb/foxx/manager.js index 4940c50bb6..85a92e9191 100644 --- a/js/server/modules/org/arangodb/foxx/manager.js +++ b/js/server/modules/org/arangodb/foxx/manager.js @@ -960,7 +960,7 @@ "configure()", [ [ "Mount path", "string" ] ], [ mount ] ); - utils.validateMount(mount); + utils.validateMount(mount, true); var app = lookupApp(mount); var invalid = app.configure(options); if (invalid.length > 0) { @@ -981,11 +981,22 @@ "configuration()", [ [ "Mount path", "string" ] ], [ mount ] ); - utils.validateMount(mount); + utils.validateMount(mount, true); var app = lookupApp(mount); return app.getConfiguration(); }; + var requireApp = function(mount) { + checkParameter( + "requireApp()", + [ [ "Mount path", "string" ] ], + [ mount ] ); + utils.validateMount(mount, true); + var app = lookupApp(mount); + require("console").log("Exports:", app._exports); + return app._exports; + }; + // ----------------------------------------------------------------------------- // --SECTION-- exports @@ -1005,6 +1016,7 @@ exports.production = setProduction; exports.configure = configure; exports.configuration = configuration; + exports.requireApp = requireApp; //////////////////////////////////////////////////////////////////////////////// /// @brief Serverside only API diff --git a/js/server/modules/org/arangodb/foxx/routing.js b/js/server/modules/org/arangodb/foxx/routing.js index b081aa0b30..2f3960a6ed 100644 --- a/js/server/modules/org/arangodb/foxx/routing.js +++ b/js/server/modules/org/arangodb/foxx/routing.js @@ -36,6 +36,8 @@ // ----------------------------------------------------------------------------- var arangodb = require("org/arangodb"); + var ArangoError = arangodb.ArangoError; + var errors = arangodb.errors; var preprocess = require("org/arangodb/foxx/preprocessor").preprocess; var _ = require("underscore"); var fs = require("fs"); @@ -43,7 +45,6 @@ var frontendDevelopmentMode = require("internal").frontendDevelopmentMode; var console = require("console"); var actions = require("org/arangodb/actions"); - var utils = require("org/arangodb/foxx/manager-utils"); // ----------------------------------------------------------------------------- // --SECTION-- private functions @@ -394,6 +395,26 @@ } }; + var routeRegEx = /^(\/:?[a-zA-Z0-9_\-%]+)+\/?$/; + + var validateRoute = function(route) { + if (route[0] !== "/") { + throw new ArangoError({ + errorNum: errors.ERROR_INVALID_MOUNTPOINT.code, + errorMessage: "Route has to start with /." + }); + } + if (!routeRegEx.test(route)) { + // Controller routes may be /. Foxxes are not allowed to + if (route.length !== 1) { + throw new ArangoError({ + errorNum: errors.ERROR_INVALID_MOUNTPOINT.code, + errorMessage: "Route parts '" + route + "' may only contain a-z, A-Z, 0-9 or _. But may start with a :" + }); + } + } + }; + // ----------------------------------------------------------------------------- // --SECTION-- public functions // ----------------------------------------------------------------------------- @@ -472,7 +493,7 @@ try { for (i in controllers) { if (controllers.hasOwnProperty(i)) { - utils.validateMount(i, true); + validateRoute(i); file = controllers[i]; // set up a context for the application start function