From 2a30b068bfc16b3fc43484cfa24e689f18f4a4f6 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Sat, 27 Jul 2013 13:43:22 +0200 Subject: [PATCH] simplified options --- .../modules/org/arangodb/foxx-manager.js | 9 ++++- js/server/modules/org/arangodb/foxx.js | 37 ++++++++----------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/js/server/modules/org/arangodb/foxx-manager.js b/js/server/modules/org/arangodb/foxx-manager.js index f1652c62c4..ad8dc2c2e5 100644 --- a/js/server/modules/org/arangodb/foxx-manager.js +++ b/js/server/modules/org/arangodb/foxx-manager.js @@ -258,7 +258,8 @@ function executeAppScript (app, name, mount, prefix) { appModule: app.createAppModule(), isDevelopment: devel, isProduction: ! devel, - options: app._options + options: app._options, + basePath: root }; var cp = appContext.collectionPrefix; @@ -471,9 +472,14 @@ function routingAalApp (app, mount, options) { if (apps.hasOwnProperty(i)) { var file = apps[i]; var devel = false; + var root; if (app._id.substr(0,4) === "dev:") { devel = true; + root = module.devAppPath(); + } + else { + root = module.appPath(); } // set up a context for the application start function @@ -486,6 +492,7 @@ function routingAalApp (app, mount, options) { collectionPrefix: prefix, // collection prefix appModule: app.createAppModule(), // app module options: options, + basePath: root, isDevelopment: devel, isProduction: ! devel, diff --git a/js/server/modules/org/arangodb/foxx.js b/js/server/modules/org/arangodb/foxx.js index 4b9558b6be..b0cfbbf4d3 100644 --- a/js/server/modules/org/arangodb/foxx.js +++ b/js/server/modules/org/arangodb/foxx.js @@ -125,8 +125,6 @@ Application = function (context, options) { } } - this.isDevelopment = context.isDevelopment; - this.isProduction = context.isProduction; this.helperCollection = {}; this.routingInfo.urlPrefix = urlPrefix; @@ -144,16 +142,14 @@ Application = function (context, options) { action: { callback: myMiddleware.stringRepresentation, options: { + name: context.name, + version: context.version, + appId: context.appId, + mount: context.mount, isDevelopment: context.isDevelopment, isProduction: context.isProduction, - app: { - appId: context.appId, - name: context.name, - version: context.version, - mount: context.mount, - prefix: context.prefix, - options: context.options - } + prefix: context.prefix, + options: context.options } } } @@ -409,7 +405,7 @@ _.extend(Application.prototype, { this.routingInfo.middleware.push({ url: {match: path}, action: { - callback: "function (req, res, opts, next) { " + String(func) + "(req, res); next(); }" + callback: "(function (req, res, opts, next) { (" + String(func) + "(req, res, opts)); next(); })" } }); }, @@ -442,7 +438,7 @@ _.extend(Application.prototype, { this.routingInfo.middleware.push({ url: {match: path}, action: { - callback: "function (req, res, opts, next) { next(); " + String(func) + "(req, res); }" + callback: "(function (req, res, opts, next) { next(); (" + String(func) + "(req, res, opts)); })" } }); }, @@ -855,35 +851,34 @@ BaseMiddleware = function (templateCollection, helperCollection) { }; var trace = options.isDevelopment; - if (!trace && options.hasOwnProperty("app") && options.app.hasOwnProperty("options")) { - trace = options.app.options.trace; + if (!trace && options.hasOwnProperty("options")) { + trace = options.options.trace; } - if (trace) { console.log("%s, incoming request from %s: %s", - options.app.mount, + options.mount, request.client.address, actions.stringifyRequestAddress(request)); } - request = _.extend(request, requestFunctions); - response = _.extend(response, responseFunctions); + _.extend(request, requestFunctions); + _.extend(response, responseFunctions); next(); if (trace) { if (response.hasOwnProperty("body")) { console.log("%s, outgoing response of type %s, body length: %d", - options.app.mount, + options.mount, response.contentType, parseInt(response.body.length, 10)); } else if (response.hasOwnProperty("bodyFromFile")) { console.log("%s, outgoing response of type %s, body file: %s", - options.app.mount, + options.mount, response.contentType, response.bodyFromFile); } else { console.log("%s, outgoing response of type %s, no body", - options.app.mount, + options.mount, response.contentType); } }