lib/aonx.js
function _postHandlers() {
  // any authentication checks first
  if(config.authentication.enabled) {
    logger.info(pkgname + "  authentication to API's enabled");
    app.all(config.api.path, function(req, res, next) {
      if(config.authentication.ignores && req.params) {
        // check if the params is in ignores list
        var matches = _.filter(req.params, function(param) {
          return _.find(config.authentication.ignores, function(ignore) {
            return param.indexOf(ignore)==0;
          });
        });
        if(matches && matches.length>0) {
          logger.debug(pkgname+"ignored auth for param:" + matches);
          return next();
        }
      }
      if(req.loggedIn) {
        return next();  // auth success go to next
      } else {
        return next(error(401, 'unauthorized access'));
      }
    });
  }

  // install api checks
  if(config.api.keycheck) {
    logger.info(pkgname + "  keycheck to API's enabled");
    // here we validate the API key 
    app.all(config.api.path, function(req, res, next){
      var key = req.query[config.api.KEYNAME] || req.body[config.api.KEYNAME];
 
      // key isnt present
      if (!key) return next(error(400, 'api key required'));
 
      // key is invalid
      if (!~config.api.keys.indexOf(key)) return next(error(401, 'invalid api key'));
 
      // all good, store req.key for route access
      req.key = key;
      next();
    });
  }

  // jsonp support for delete, put & post (partial post)
  if(config.server.jsonp) {
    logger.info(pkgname + "  jsonp support on api's enabled");
    // check if callback is there along with method
    app.all(config.api.path, function(req, res, next) {
      if(req.query && req.query['callback'] && req.query['_method']) {
        // lets rewrite the method, especially PUT/DELETE/POST
        req.method=req.query['_method'];
        logger.debug(pkgname + "jsonp request converted:"+req.query);
      }
      next();
    });
  }

  var api = {
    index: function(req,res) {
      res.json({app:config.app.title, version:config.app.version});
    }
  };
  global.apiresource = app.resource('api', api);
  logger.info(pkgname + "  api handler added");
  logger.debug(pkgname + "init complete");
}
function _postHandlers() {
  // any authentication checks first
  if(config.authentication.enabled) {
    logger.info(pkgname + "  authentication to API's enabled");
    app.all(config.api.path, function(req, res, next) {
      if(config.authentication.ignores && req.params) {
        // check if the params is in ignores list
        var matches = _.filter(req.params, function(param) {
          return _.find(config.authentication.ignores, function(ignore) {
            return param.indexOf(ignore)==0;
          });
        });
        if(matches && matches.length>0) {
          logger.debug(pkgname+"ignored auth for param:" + matches);
          return next();
        }
      }
      if(req.loggedIn) {
        return next();  // auth success go to next
      } else {
        return next(error(401, 'unauthorized access'));
      }
    });
  }

  // install api checks
  if(config.api.keycheck) {
    logger.info(pkgname + "  keycheck to API's enabled");
    // here we validate the API key 
    app.all(config.api.path, function(req, res, next){
      var key = req.query[config.api.KEYNAME] || req.body[config.api.KEYNAME];
 
      // key isnt present
      if (!key) return next(error(400, 'api key required'));
 
      // key is invalid
      if (!~config.api.keys.indexOf(key)) return next(error(401, 'invalid api key'));
 
      // all good, store req.key for route access
      req.key = key;
      next();
    });
  }

  // jsonp support for delete, put & post (partial post)
  if(config.server.jsonp) {
    logger.info(pkgname + "  jsonp support on api's enabled");
    // check if callback is there along with method
    app.all(config.api.path, function(req, res, next) {
      if(req.query && req.query['callback'] && req.query['_method']) {
        // lets rewrite the method, especially PUT/DELETE/POST
        req.method=req.query['_method'];
        logger.debug(pkgname + "jsonp request converted:"+req.query);
      }
      next();
    });
  }

  var api = {
    index: function(req,res) {
      res.json({app:config.app.title, version:config.app.version});
    }
  };
  global.apiresource = app.resource('api', api);
  logger.info(pkgname + "  api handler added");
  logger.debug(pkgname + "init complete");
}
function _postHandlers ( ) { // any authentication checks first if ( config . authentication . enabled ) { logger . info ( pkgname + "  authentication to API's enabled" ) ; app . all ( config . api . path , function ( req , res , next ) { if ( config . authentication . ignores && req . params ) { // check if the params is in ignores list var matches = _ . filter ( req . params , function ( param ) { return _ . find ( config . authentication . ignores , function ( ignore ) { return param . indexOf ( ignore ) == 0 ; } ) ; } ) ; if ( matches && matches . length > 0 ) { logger . debug ( pkgname + "ignored auth for param:" + matches ) ; return next ( ) ; } } if ( req . loggedIn ) { return next ( ) ; // auth success go to next } else { return next ( error ( 401 , 'unauthorized access' ) ) ; } } ) ; } // install api checks if ( config . api . keycheck ) { logger . info ( pkgname + "  keycheck to API's enabled" ) ; // here we validate the API key  app . all ( config . api . path , function ( req , res , next ) { var key = req . query [ config . api . KEYNAME ] || req . body [ config . api . KEYNAME ] ; // key isnt present if ( ! key ) return next ( error ( 400 , 'api key required' ) ) ; // key is invalid if ( ! ~ config . api . keys . indexOf ( key ) ) return next ( error ( 401 , 'invalid api key' ) ) ; // all good, store req.key for route access req . key = key ; next ( ) ; } ) ; } // jsonp support for delete, put & post (partial post) if ( config . server . jsonp ) { logger . info ( pkgname + "  jsonp support on api's enabled" ) ; // check if callback is there along with method app . all ( config . api . path , function ( req , res , next ) { if ( req . query && req . query [ 'callback' ] && req . query [ '_method' ] ) { // lets rewrite the method, especially PUT/DELETE/POST req . method = req . query [ '_method' ] ; logger . debug ( pkgname + "jsonp request converted:" + req . query ) ; } next ( ) ; } ) ; } var api = { index : function ( req , res ) { res . json ( { app : config . app . title , version : config . app . version } ) ; } } ; global . apiresource = app . resource ( 'api' , api ) ; logger . info ( pkgname + "  api handler added" ) ; logger . debug ( pkgname + "init complete" ) ; }
all post handlers go here
all post handlers go here