1
0
Fork 0

added frontend-development switch

This commit is contained in:
Frank Celler 2014-02-19 14:28:51 +01:00
parent da7d64bba9
commit c779325b5d
6 changed files with 133 additions and 31 deletions

View File

@ -27,10 +27,12 @@
#include "ApplicationV8.h"
#include "Actions/actions.h"
#include "ApplicationServer/ApplicationServer.h"
#include "Basics/ConditionLocker.h"
#include "Basics/FileUtils.h"
#include "Basics/MutexLocker.h"
#include "Basics/Mutex.h"
#include "Basics/MutexLocker.h"
#include "Basics/ReadLocker.h"
#include "Basics/StringUtils.h"
#include "Basics/Thread.h"
@ -44,11 +46,11 @@
#include "V8Server/v8-query.h"
#include "V8Server/v8-vocbase.h"
#include "VocBase/server.h"
#include "Actions/actions.h"
using namespace triagens;
using namespace triagens::basics;
using namespace triagens::arango;
using namespace triagens::rest;
using namespace std;
////////////////////////////////////////////////////////////////////////////////
@ -201,6 +203,7 @@ ApplicationV8::ApplicationV8 (TRI_server_t* server)
_devAppPath(),
_useActions(true),
_developmentMode(false),
_frontendDevelopmentMode(false),
_performUpgrade(false),
_skipUpgrade(false),
_gcInterval(1000),
@ -570,11 +573,16 @@ void ApplicationV8::setupOptions (map<string, basics::ProgramOptionsDescription>
("javascript.dev-app-path", &_devAppPath, "directory for Foxx applications (development mode)")
("javascript.startup-directory", &_startupPath, "path to the directory containing JavaScript startup scripts")
("javascript.v8-options", &_v8Options, "options to pass to v8")
// deprecated options
("javascript.action-directory", &DeprecatedPath, "path to the JavaScript action directory (deprecated)")
("javascript.modules-path", &DeprecatedPath, "one or more directories separated by semi-colons (deprecated)")
("javascript.package-path", &DeprecatedPath, "one or more directories separated by semi-colons (deprecated)")
;
options[ApplicationServer::OPTIONS_HIDDEN]
("javascript.frontend-development", &_frontendDevelopmentMode, "allows rebuild frontend assets")
;
}
////////////////////////////////////////////////////////////////////////////////
@ -775,6 +783,7 @@ bool ApplicationV8::prepareV8Instance (const size_t i) {
TRI_AddGlobalVariableVocbase(context->_context, "APP_PATH", v8::String::New(_appPath.c_str(), _appPath.size()));
TRI_AddGlobalVariableVocbase(context->_context, "DEV_APP_PATH", v8::String::New(_devAppPath.c_str(), _devAppPath.size()));
TRI_AddGlobalVariableVocbase(context->_context, "DEVELOPMENT_MODE", v8::Boolean::New(_developmentMode));
TRI_AddGlobalVariableVocbase(context->_context, "FE_DEVELOPMENT_MODE", v8::Boolean::New(_frontendDevelopmentMode));
}
// set global flag before loading system files

View File

@ -429,11 +429,17 @@ namespace triagens {
bool _useActions;
////////////////////////////////////////////////////////////////////////////////
/// @brief use development mode
/// @brief enables development mode
////////////////////////////////////////////////////////////////////////////////
bool _developmentMode;
////////////////////////////////////////////////////////////////////////////////
/// @brief enables frontend development mode
////////////////////////////////////////////////////////////////////////////////
bool _frontendDevelopmentMode;
////////////////////////////////////////////////////////////////////////////////
/// @brief perform a database upgrade
///

View File

@ -1,4 +1,5 @@
<body>
HHALO
<nav class="navbar">
<div class="resizecontainer">
<div class="navlogo">

View File

@ -127,6 +127,23 @@
SYS_LOG("warning", "################################################################################");
}
////////////////////////////////////////////////////////////////////////////////
/// @brief frontendDevelopmentMode
////////////////////////////////////////////////////////////////////////////////
exports.frontendDevelopmentMode = false;
if (typeof FE_DEVELOPMENT_MODE !== "undefined") {
exports.frontendDevelopmentMode = FE_DEVELOPMENT_MODE;
delete FE_DEVELOPMENT_MODE;
}
if (exports.frontendDevelopmentMode && exports.threadNumber === 0) {
SYS_LOG("warning", "################################################################################");
SYS_LOG("warning", "frontend development mode is active, never use this in production");
SYS_LOG("warning", "################################################################################");
}
////////////////////////////////////////////////////////////////////////////////
/// @brief logfilePath
////////////////////////////////////////////////////////////////////////////////

View File

@ -127,6 +127,23 @@
SYS_LOG("warning", "################################################################################");
}
////////////////////////////////////////////////////////////////////////////////
/// @brief frontendDevelopmentMode
////////////////////////////////////////////////////////////////////////////////
exports.frontendDevelopmentMode = false;
if (typeof FE_DEVELOPMENT_MODE !== "undefined") {
exports.frontendDevelopmentMode = FE_DEVELOPMENT_MODE;
delete FE_DEVELOPMENT_MODE;
}
if (exports.frontendDevelopmentMode && exports.threadNumber === 0) {
SYS_LOG("warning", "################################################################################");
SYS_LOG("warning", "frontend development mode is active, never use this in production");
SYS_LOG("warning", "################################################################################");
}
////////////////////////////////////////////////////////////////////////////////
/// @brief logfilePath
////////////////////////////////////////////////////////////////////////////////

View File

@ -36,6 +36,7 @@ var fs = require("fs");
var _ = require("underscore");
var executeGlobalContextFunction = require("internal").executeGlobalContextFunction;
var frontendDevelopmentMode = require("internal").frontendDevelopmentMode;
var checkParameter = arangodb.checkParameter;
var transformScript = require("org/arangodb/foxx/preprocessor").preprocess;
@ -326,6 +327,80 @@ function buildAssetContent (app, assets, basePath) {
return content;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief installs an asset for an app
////////////////////////////////////////////////////////////////////////////////
function buildFileAsset (app, path, basePath, asset) {
var content = buildAssetContent(app, asset.files, basePath);
var type;
var route;
// -----------------------------------------------------------------------------
// content-type detection
// -----------------------------------------------------------------------------
// contentType explicitly specified for asset
if (asset.hasOwnProperty("contentType") && asset.contentType !== '') {
type = asset.contentType;
}
// path contains a dot, derive content type from path
else if (path.match(/\.[a-zA-Z0-9]+$/)) {
type = arangodb.guessContentType(path);
}
// path does not contain a dot,
// derive content type from included asset names
else if (asset.files.length > 0) {
type = arangodb.guessContentType(asset.files[0]);
}
// use built-in defaulti content-type
else {
type = arangodb.guessContentType("");
}
// -----------------------------------------------------------------------------
// return content
// -----------------------------------------------------------------------------
return { contentType: type, body: content };
}
////////////////////////////////////////////////////////////////////////////////
/// @brief generates development asset action
////////////////////////////////////////////////////////////////////////////////
function buildDevelopmentAssetRoute (app, path, basePath, asset) {
var internal = require("internal");
return {
url: { match: path },
action: {
callback: function (req, res) {
var c = buildFileAsset(app, path, basePath, asset);
res.contentType = c.contentType;
res.body = c.body;
}
}
};
}
////////////////////////////////////////////////////////////////////////////////
/// @brief generates asset action
////////////////////////////////////////////////////////////////////////////////
function buildAssetRoute (app, path, basePath, asset) {
var c = buildFileAsset(app, path, basePath, asset);
return {
url: { match: path },
content: { contentType: c.contentType, body: c.body }
};
}
////////////////////////////////////////////////////////////////////////////////
/// @brief installs the assets of an app
////////////////////////////////////////////////////////////////////////////////
@ -352,39 +427,16 @@ function installAssets (app, routes) {
basePath = asset.basePath;
}
normalized = arangodb.normalizeURL("/" + path);
if (asset.hasOwnProperty('files')) {
var content = buildAssetContent(app, asset.files, basePath);
var type;
normalized = arangodb.normalizeURL("/" + path);
// content-type detection
// ----------------------
if (asset.hasOwnProperty("contentType") && asset.contentType !== '') {
// contentType explicitly specified for asset
type = asset.contentType;
}
else if (normalized.match(/\.[a-zA-Z0-9]+$/)) {
// path contains a dot
// derive content type from path
type = arangodb.guessContentType(normalized);
}
else if (asset.files.length > 0) {
// path does not contain a dot
// derive content type from included asset names
type = arangodb.guessContentType(asset.files[0]);
if (frontendDevelopmentMode) {
route = buildDevelopmentAssetRoute(app, normalized, basePath, asset);
}
else {
// use built-in defaulti content-type
type = arangodb.guessContentType("");
route = buildAssetRoute(app, normalized, basePath, asset);
}
route = {
url: { match: normalized },
content: { contentType: type, body: content }
};
routes.routes.push(route);
}
}