Example #1
0
 /**
  * getting data on method and command
  * 
  * @param params {name, method, body, requrest, response}
  */
 function sendData(params, callback) {
     var p       = params,
         isFS    = Util.isContainStrAtBegin(p.name, CloudFunc.FS),
         isMD    = Util.isContainStrAtBegin(p.name, '/markdown');
     
     if (isFS)
         onFS(params, callback);
     else if (isMD)
         markdown(p.name, p.request, function(error, data) {
             callback(error, {notLog: true}, data);
         });
     else
         switch(p.request.method) {
         case 'GET':
             onGET(params, callback);
             break;
             
         case 'PUT':
             pipe.getBody(p.request, function(error, body) {
                 if (error)
                     callback(error);
                 else
                     onPUT(p.name, body, callback);
             });
             break;
         }
 }
Example #2
0
 /**
  * routing of server queries
  */
 function route(request, response, callback) {
     var name, p, isAuth, isFS, path;
     
     Util.checkArgs(arguments, ['req', 'res', 'callback']);
     
     name    = ponse.getPathName(request);
     isAuth  = Util.strCmp(name, ['/auth', '/auth/github']);
     isFS    = Util.strCmp(name, '/') || Util.isContainStrAtBegin(name, FS);
     
     p       = {
         request     : request,
         response    : response,
         gzip        : true,
         name        : name
     };
     
     if (!isAuth && !isFS)
         callback();
     else if (isAuth) {
         Util.log('* Routing' + '-> ' + name);
         
         p.name = DIR_HTML + name + '.html';
         ponse.sendFile(p);
     } else if (isFS) {
         name    = Util.rmStrOnce(name, CloudFunc.FS) || '/';
         path    = mellow.convertPath(name);
         
         mellow.read(path, function(error, dir) {
             if (dir)
                 dir.path = format.addSlashToEnd(name);
             
             if (error)
                 if (error.code !== 'ENOTDIR')
                     ponse.sendError(error, p);
                 else
                     fs.realpath(path, function(error, pathReal) {
                         if (!error)
                             p.name = pathReal;
                         else
                             p.name = path;
                         
                         p.gzip = false;
                         ponse.sendFile(p);
                     });
             else
                 buildIndex(dir, function(error, data) {
                     var NOT_LOG = true;
                     
                     p.name = PATH_INDEX;
                     
                     if (error)
                         ponse.sendError(error, p);
                     else
                         ponse.send(data, p, NOT_LOG);
                 });
         });
     }
 }