mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into devel
This commit is contained in:
commit
c3cf842d72
|
@ -307,9 +307,9 @@ The simplest dynamic action is:
|
||||||
|
|
||||||
{ action: { do: "org/arangodb/actions/echoRequest" } }
|
{ action: { do: "org/arangodb/actions/echoRequest" } }
|
||||||
|
|
||||||
It is not possible to store functions directly in the routing table, but you can
|
It is not advisable to store functions directly in the routing table. It is
|
||||||
call functions defined in modules. In the above example the function can be
|
better to call functions defined in modules. In the above example the function
|
||||||
accessed from JavaScript as:
|
can be accessed from JavaScript as:
|
||||||
|
|
||||||
require("org/arangodb/actions").echoRequest
|
require("org/arangodb/actions").echoRequest
|
||||||
|
|
||||||
|
@ -406,6 +406,17 @@ The definition
|
||||||
|
|
||||||
is a short-cut for a prefix controller definition.
|
is a short-cut for a prefix controller definition.
|
||||||
|
|
||||||
|
Function Action {#UserManualActionsFunctionAction}
|
||||||
|
--------------------------------------------------
|
||||||
|
|
||||||
|
You can also store a function directly in the routing table.
|
||||||
|
|
||||||
|
For example
|
||||||
|
|
||||||
|
arangosh> db._routing.save({
|
||||||
|
........> url: "/hello/echo",
|
||||||
|
........> action: { function: "function(req,res) {res.statusCode=200; res.body='Hallo'}" } });
|
||||||
|
|
||||||
Requests and Responses {#UserManualActionsReqRes}
|
Requests and Responses {#UserManualActionsReqRes}
|
||||||
=================================================
|
=================================================
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ TOC {#UserManualActionsTOC}
|
||||||
- @ref UserManualActionsContentAction
|
- @ref UserManualActionsContentAction
|
||||||
- @ref UserManualActionsContentController
|
- @ref UserManualActionsContentController
|
||||||
- @ref UserManualActionsContentPrefix
|
- @ref UserManualActionsContentPrefix
|
||||||
|
- @ref UserManualActionsFunctionAction
|
||||||
- @ref UserManualActionsReqRes
|
- @ref UserManualActionsReqRes
|
||||||
- @ref UserManualActionsModify
|
- @ref UserManualActionsModify
|
||||||
- @ref UserManualActionsHandlers
|
- @ref UserManualActionsHandlers
|
||||||
|
|
|
@ -158,6 +158,37 @@ ArangoApp.prototype._PRINT = function (route) {
|
||||||
/// @{
|
/// @{
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief mounts one function directly
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ArangoApp.prototype.mountStaticFunction = function (url, func, methods) {
|
||||||
|
if (url === "") {
|
||||||
|
url = "/";
|
||||||
|
}
|
||||||
|
else if (url[0] !== '/') {
|
||||||
|
url = "/" + url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (methods === undefined) {
|
||||||
|
methods = [ "GET", "HEAD" ];
|
||||||
|
}
|
||||||
|
|
||||||
|
pages = {
|
||||||
|
type: "StaticFunction",
|
||||||
|
key: url,
|
||||||
|
url: { match: url },
|
||||||
|
action: {
|
||||||
|
'function': String(func),
|
||||||
|
methods: methods,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.updateRoute(pages);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief mounts one page directly
|
/// @brief mounts one page directly
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -216,6 +216,8 @@ function lookupCallbackAction (route, action) {
|
||||||
var func;
|
var func;
|
||||||
var module;
|
var module;
|
||||||
var joined;
|
var joined;
|
||||||
|
var defn;
|
||||||
|
var env;
|
||||||
var httpMethods = {
|
var httpMethods = {
|
||||||
'get': exports.GET,
|
'get': exports.GET,
|
||||||
'head': exports.HEAD,
|
'head': exports.HEAD,
|
||||||
|
@ -225,10 +227,50 @@ function lookupCallbackAction (route, action) {
|
||||||
'patch': exports.PATCH
|
'patch': exports.PATCH
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// .............................................................................
|
||||||
|
// short-cut for prefix controller
|
||||||
|
// .............................................................................
|
||||||
|
|
||||||
if (typeof action === 'string') {
|
if (typeof action === 'string') {
|
||||||
return lookupCallbackAction(route, { prefixController: action });
|
return lookupCallbackAction(route, { prefixController: action });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// .............................................................................
|
||||||
|
// function
|
||||||
|
// .............................................................................
|
||||||
|
|
||||||
|
if (action.hasOwnProperty('function')) {
|
||||||
|
defn = "func = " + action['function'];
|
||||||
|
env = {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
internal.execute(defn, env, route);
|
||||||
|
|
||||||
|
if (env.hasOwnProperty("func")) {
|
||||||
|
func = env.func;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
func = notImplementedFunction(route,
|
||||||
|
"could not define function '" + action['function']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
func = errorFunction(route,
|
||||||
|
"an error occurred while loading function '"
|
||||||
|
+ action['function'] + "': " + String(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
controller: func,
|
||||||
|
options: action.options || {},
|
||||||
|
methods: action.methods || exports.ALL_METHODS
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// .............................................................................
|
||||||
|
// function from module
|
||||||
|
// .............................................................................
|
||||||
|
|
||||||
if (action.hasOwnProperty('do')) {
|
if (action.hasOwnProperty('do')) {
|
||||||
path = action['do'].split("/");
|
path = action['do'].split("/");
|
||||||
name = path.pop();
|
name = path.pop();
|
||||||
|
@ -272,6 +314,10 @@ function lookupCallbackAction (route, action) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// .............................................................................
|
||||||
|
// controller module
|
||||||
|
// .............................................................................
|
||||||
|
|
||||||
if (action.hasOwnProperty('controller')) {
|
if (action.hasOwnProperty('controller')) {
|
||||||
try {
|
try {
|
||||||
module = require(action.controller);
|
module = require(action.controller);
|
||||||
|
@ -322,6 +368,10 @@ function lookupCallbackAction (route, action) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// .............................................................................
|
||||||
|
// prefix controller
|
||||||
|
// .............................................................................
|
||||||
|
|
||||||
if (action.hasOwnProperty('prefixController')) {
|
if (action.hasOwnProperty('prefixController')) {
|
||||||
var prefixController = action.prefixController;
|
var prefixController = action.prefixController;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue