lib/camp.js
function ajaxUnit (server) {
  var ajax = server.ajax = new EventEmitter();
  // Register events to be fired before loading the ajax data.
  var ajaxReq = server.ajaxReq = new EventEmitter();

  return function ajaxLayer (req, res, next) {
    if (req.path[1] !== '$') { return next(); }
    var action = req.path.slice(2);

    if (ajax.listeners(action).length <= 0) { return next(); }

    res.setHeader('Content-Type', mime.json);

    ajaxReq.emit(action, req.ask);
    // Get all data requests.
    getQueries(req, function(err) {
      if (err == null) {
        ajax.emit(action, req.query, function ajaxEnd(data) {
          res.compressed().end(JSON.stringify(data || {}));
        }, req.ask);
      } else {
        log('While parsing', req.url + ':\n'
          + err
          , 'error');
        return next();
      }
    });
  };
}
function ajaxUnit (server) {
  var ajax = server.ajax = new EventEmitter();
  // Register events to be fired before loading the ajax data.
  var ajaxReq = server.ajaxReq = new EventEmitter();

  return function ajaxLayer (req, res, next) {
    if (req.path[1] !== '$') { return next(); }
    var action = req.path.slice(2);

    if (ajax.listeners(action).length <= 0) { return next(); }

    res.setHeader('Content-Type', mime.json);

    ajaxReq.emit(action, req.ask);
    // Get all data requests.
    getQueries(req, function(err) {
      if (err == null) {
        ajax.emit(action, req.query, function ajaxEnd(data) {
          res.compressed().end(JSON.stringify(data || {}));
        }, req.ask);
      } else {
        log('While parsing', req.url + ':\n'
          + err
          , 'error');
        return next();
      }
    });
  };
}
function ajaxUnit ( server ) { var ajax = server . ajax = new EventEmitter ( ) ; // Register events to be fired before loading the ajax data. var ajaxReq = server . ajaxReq = new EventEmitter ( ) ; return function ajaxLayer ( req , res , next ) { if ( req . path [ 1 ] !== '$' ) { return next ( ) ; } var action = req . path . slice ( 2 ) ; if ( ajax . listeners ( action ) . length <= 0 ) { return next ( ) ; } res . setHeader ( 'Content-Type' , mime . json ) ; ajaxReq . emit ( action , req . ask ) ; // Get all data requests. getQueries ( req , function ( err ) { if ( err == null ) { ajax . emit ( action , req . query , function ajaxEnd ( data ) { res . compressed ( ) . end ( JSON . stringify ( data || { } ) ) ; } , req . ask ) ; } else { log ( 'While parsing' , req . url + ':\n' + err , 'error' ) ; return next ( ) ; } } ) ; } ; }
Ajax unit.
Ajax unit .