1
0
Fork 0

Applied default configuration to foxx apps. Fixed RegEx for allowed routes. Started to fix exports.

This commit is contained in:
Michael Hackstein 2015-02-17 17:25:04 +01:00
parent d9bc1be027
commit 3c96aa8c6a
4 changed files with 62 additions and 5 deletions

View File

@ -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));
};
// -----------------------------------------------------------------------------

View File

@ -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")) {

View File

@ -960,7 +960,7 @@
"configure(<mount>)",
[ [ "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>)",
[ [ "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>)",
[ [ "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

View File

@ -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