Permalink
Browse files

server-node: Cleaned up internals for API processing

  • Loading branch information...
andersevenrud committed Jun 17, 2016
1 parent 12ed12d commit 0290f268ec2e772b48433f699dab0c05374468e7
@@ -1,7 +1,7 @@
(function() {
exports.register = function(apiNamespace, vfsNamespace, instance) {
API.broadway = function(args, callback, request, response) {
API.broadway = function(server, args, callback) {
callback(false, false);
};
};
@@ -37,11 +37,9 @@
/**
* Login Wrapper. This is just a placeholder. The function is bound in the handler
*
* @param Object server Server object
* @param Object args API Call Arguments
* @param Function callback Callback function => fn(error, result)
* @param Object request Server request object
* @param Object response Server response object
* @param Object config Server configuration object
*
* @option args String username Username
* @option args String password Password
@@ -50,54 +48,48 @@
*
* @api api.login
*/
module.exports.login = function(args, callback, request, response, config) {
module.exports.login = function(server, args, callback) {
callback('No handler assigned', {});
};
/**
* Logout Wrapper. This is just a placeholder. The function is bound in the handler
*
* @param Object server Server object
* @param Object args API Call Arguments
* @param Function callback Callback function => fn(error, result)
* @param Object request Server request object
* @param Object response Server response object
* @param Object config Server configuration object
*
* @return void
*
* @api api.logout
*/
module.exports.logout = function(args, callback, request, response, config) {
module.exports.logout = function(server, args, callback) {
callback('No handler assigned', {});
};
/**
* Settings storing Wrapper. This is just a placeholder. The function is bound in the handler
*
* @param Object server Server object
* @param Object args API Call Arguments
* @param Function callback Callback function => fn(error, result)
* @param Object request Server request object
* @param Object response Server response object
* @param Object config Server configuration object
*
* @option args Object settings Settings Tree
*
* @return void
*
* @api api.settings
*/
module.exports.settings = function(args, callback, request, response, config) {
module.exports.settings = function(server, args, callback) {
callback('No handler assigned', {});
};
/**
* Application API Call
*
* @param Object server Server object
* @param Object args API Call Arguments
* @param Function callback Callback function => fn(error, result)
* @param Object request Server request object
* @param Object response Server response object
* @param Object config Server configuration object
*
* @option args String path Package Path (ex: default/FileManager)
* @option args String method API Method name
@@ -107,20 +99,20 @@
*
* @api api.application
*/
module.exports.application = function(args, callback, request, response, config, handler) {
module.exports.application = function(server, args, callback) {
var apath = args.path || null;
var ameth = args.method || null;
var aargs = args['arguments'] || [];
var aroot = _path.join(config.repodir, apath);
var aroot = _path.join(server.config.repodir, apath);
var fpath = _path.join(aroot, 'api.js');
try {
require(fpath)[ameth](aargs, function(error, result) {
callback(error, result);
}, request, response, config, handler);
}, server.request, server.response, server.config, server.handler);
} catch ( e ) {
if ( config.logging !== false ) {
if ( server.config.logging !== false ) {
console.warn(e.stack, e.trace);
}
callback('Application API error or missing: ' + e.toString(), null);
@@ -136,11 +128,9 @@
* query string was defined in the url, this method will try to transform the
* given body data and append to the url.
*
* @param Object server Server object
* @param Object args API Call Arguments
* @param Function callback Callback function => fn(error, result)
* @param Object request Server request object
* @param Object response Server response object
* @param Object config Server configuration object
*
* @option args String method HTTP Call method (GET/POST/HEAD)
* @option args String url HTTP Call URL
@@ -157,7 +147,7 @@
*
* @api api.curl
*/
module.exports.curl = function(args, callback, request, response, config) {
module.exports.curl = function(server, args, callback) {
var url = args.url;
if ( !url ) {
Oops, something went wrong.

0 comments on commit 0290f26

Please sign in to comment.