Commits

kai zhu  committed 5b36a53

rename HTTP_HANDLER to HTTP_ROUTER.

  • Participants
  • Parent commits 6748edb

Comments (0)

Files changed (3)

File moduleMain.js2

 /*
 CHANGELOG
-hide / show xhr progress after 1000 ms delay. rewriting db. remove imgAjaxLoader.
+rename HTTP_HANDLER to HTTP_ROUTER.
 
 TODO
 add client-side interactive tests.
         reader.removeListener('end', onEnd);
         reader.removeListener('error', onEnd);
       }
-      reader.on('close', onEnd);
-      reader.on('data', onData);
-      reader.on('end', onEnd);
-      reader.on('error', onEnd);
+      reader.addListener('close', onEnd);
+      reader.addListener('data', onData);
+      reader.addListener('end', onEnd);
+      reader.addListener('error', onEnd);
     },
 
     stringFormat: function (template, options) {
         EXPORTS.shell(bb);
         return;
       case 'error':
-        try {
-          EXPORTS.requireVm.runInThisContext(bb);
-        } catch (errEval) {
-          console.error(errEval.stack);
-        }
+        try { EXPORTS.requireVm.runInThisContext(bb); } catch (errEval) { console.error(errEval.stack); }
         return;
       case 'git':
         EXPORTS.shell('git ' + (bb === 'log' ? 'log | head -n 18' : bb));
         return;
       case 'grep':
         EXPORTS.shell(
-          'grep -in ' + JSON.stringify(bb) + ' $(find . -type f | grep -v "/\\.\\|\\b\\(\\.\\d\\|build\\|coverage\\|docs\\|min\\|node_modules\\|rollup\\|swp\\|test\\|tmp\\)\\b")'
+          'grep -in ' + JSON.stringify(bb) + ' $(find . -type f | grep -v "/\\.\\|\\b\\(\\.\\d\\|archive\\|build\\|coverage\\|docs\\|min\\|node_modules\\|rollup\\|swp\\|test\\|tmp\\)\\b")'
         );
         return;
       //// print function
     _init: function () {
       //// EXPORTS
       EXPORTS.exportLocal(local);
-      EXPORTS.HTTP_HANDLER = EXPORTS.HTTP_HANDLER || {};
-      EXPORTS.HTTP_HANDLER['/echo'] = EXPORTS.handlerEcho;
-      EXPORTS.HTTP_HANDLER['/http:'] = EXPORTS.handlerHttpProxy;
-      EXPORTS.HTTP_HANDLER['/https:'] = EXPORTS.handlerHttpProxy;
-      EXPORTS.HTTP_HANDLER['/public'] = EXPORTS.handlerStatic;
       EXPORTS.HTTP_HISTORY = EXPORTS.HTTP_HISTORY || EXPORTS.arrayZeros(8);
+      EXPORTS.HTTP_ROUTER = EXPORTS.HTTP_ROUTER || {};
+      EXPORTS.HTTP_ROUTER['/echo'] = EXPORTS.routerEcho;
+      EXPORTS.HTTP_ROUTER['/http:'] = EXPORTS.routerHttpProxy;
+      EXPORTS.HTTP_ROUTER['/https:'] = EXPORTS.routerHttpProxy;
+      EXPORTS.HTTP_ROUTER['/public'] = EXPORTS.routerStatic;
       EXPORTS.HTTP_SECURITY = EXPORTS.HTTP_SECURITY || {};
       EXPORTS.HTTP_SECURITY['/echo'] = EXPORTS.HTTP_SECURITY['/echo'] || true;
       EXPORTS.HTTP_SECURITY['/http:'] = EXPORTS.HTTP_SECURITY['/http:'] || true;
         //// middleware - security
         EXPORTS.HTTP_APP.use(EXPORTS.middlewareSecurity);
         //// middleware - dynamic path handler
-        EXPORTS.HTTP_APP.use(EXPORTS.middlewarePath);
+        EXPORTS.HTTP_APP.use(EXPORTS.middlewareRouter);
       }
     },
 
-    handlerEcho: function (request, response) {
+    routerEcho: function (request, response) {
       //// echo's back request along with post data if any
       var headers, name;
       response.writeHead(200, {'content-type': 'text/plain'});
       request.pipe(response);
     },
 
-    handlerHttpProxy: function (request, response, next) {
+    routerHttpProxy: function (request, response, next) {
       var key, options = {
         url: /http.*/.exec(request.url)[0],
         headers: {},
       request.pipe(EXPORTS.httpRequest(options));
     },
 
-    handlerStatic: function (request, response, next) {
+    routerStatic: function (request, response, next) {
       var readStream, path;
       path = request.absolutePath;
       //// OPTIMIZATION - client-side cache versioning
       }
     },
 
-    middlewarePath: function (request, response, next) {
+    middlewareRouter: function (request, response, next) {
       var path;
       //// debug history of requests / responses
       EXPORTS.request = request;
       EXPORTS.HTTP_HISTORY.pop();
       //// dyanamic path handler
       for (path = request.absolutePath; path.length > 1; path = path.replace(/\/+[^\/]*$/, '')) {
-        if (EXPORTS.HTTP_HANDLER.hasOwnProperty(path)) {
-          EXPORTS.HTTP_HANDLER[path](request, response, next);
+        if (EXPORTS.HTTP_ROUTER.hasOwnProperty(path)) {
+          EXPORTS.HTTP_ROUTER[path](request, response, next);
           return;
         }
       }
       //// EXPORTS
       EXPORTS.exportLocal(local);
       EXPORTS.ADMIN_BASIC_AUTH = EXPORTS.ADMIN_BASIC_AUTH || new Buffer(Math.random().toString(16).slice(2) + ':' + Math.random().toString(16).slice(2)).toString('base64');
-      EXPORTS.HTTP_HANDLER['/admin'] = EXPORTS.handlerStatic;
-      EXPORTS.HTTP_SECURITY['/admin'] = EXPORTS.handlerAdminBasicAuth;
+      EXPORTS.HTTP_ROUTER['/admin'] = EXPORTS.routerStatic;
+      EXPORTS.HTTP_SECURITY['/admin'] = EXPORTS.routerAdminBasicAuth;
     },
 
-    handlerAdminEval: function (request, response, next) {
+    routerAdminEval: function (request, response, next) {
       EXPORTS.streamReadBuffer(request, function (err, data) {
         if (err) {
           next(err);
       EXPORTS.ADMIN_BASIC_AUTH = new Buffer(userPass).toString('base64');
     },
 
-    handlerAdminBasicAuth: function (request, response, next) {
+    routerAdminBasicAuth: function (request, response, next) {
       if (/\S*$/.exec(request.headers.authorization || '')[0] === EXPORTS.ADMIN_BASIC_AUTH) {
         next();
         return;
       EXPORTS.FS_TMP = EXPORTS.FS_TMP || '/tmp/' + EXPORTS.FS_CWD.replace(/\W/g, '_') + '_' + EXPORTS.HTTP_PORT;
       EXPORTS.FS_CACHE = EXPORTS.FS_CACHE || EXPORTS.FS_TMP + '/cache';
       EXPORTS.FS_DB = EXPORTS.FS_DB || EXPORTS.FS_TMP + '/db';
-      EXPORTS.HTTP_HANDLER['/admin/db'] = EXPORTS.handlerDb;
+      EXPORTS.HTTP_ROUTER['/admin/db'] = EXPORTS.routerDb;
       //// create directories
       EXPORTS.requireFsExtra.mkdirpSync(EXPORTS.FS_CACHE);
       EXPORTS.requireFsExtra.mkdirpSync(EXPORTS.FS_DB);
       });
     },
 
-    handlerDb: function (request, response, next) {
+    routerDb: function (request, response, next) {
       EXPORTS.streamReadBuffer(request, function (err, data) {
         EXPORTS.dbAction(request.absolutePath, data, function (err, data) {
           if (err) {
     _init: function () {
       //// EXPORTS
       EXPORTS.exportLocal(local);
-      EXPORTS.HTTP_HANDLER['/admin/test/progress'] = EXPORTS.handlerTestProgress;
+      EXPORTS.HTTP_ROUTER['/admin/test/progress'] = EXPORTS.routerTestProgress;
       //// http tests
       if (!EXPORTS.HTTP_SERVER) { return; }
       EXPORTS.TEST_HTTP.proxy = function () {
       EXPORTS.startTest();
     },
 
-    handlerTestProgress: function (request, response, next) {
+    routerTestProgress: function (request, response, next) {
       //// test xhr progress
       var ii = EXPORTS.randomInt(100);
       function recurse() {

File moduleMisc.js2

       local.dbAction('/list', null, local._dbListTables);
     },
 
-    eventHandler: function (evt) {
+    onEvent: function (evt) {
       var ii, target = evt.target;
       //// debug
       window.evt = evt;
 
     _init: function () {
       var arr, ii;
-      //// event handlers
-      document.body.addEventListener('click', local.eventHandler);
+      //// event handling
+      document.body.addEventListener('click', local.onEvent);
       //// auto index elements by id
       arr = document.querySelectorAll('[id]');
       for (ii = 0; ii < arr.length; ii += 1) { dom[arr[ii].id] = arr[ii]; }
         '</a>';
       local._parent.appendChild(self.child);
       //// event handling
-      function handlerEvent(evt) {
+      function onEvent(evt) {
         switch (evt.type) {
         case 'progress':
           local._xhrProgressEventProgress(evt, self);
       self.bar = self.child.getElementsByClassName('bar')[0];
       self.child.xhr = xhr = new XMLHttpRequest();
       self.loaded = self.progress = self.ratio = 0;
-      xhr.addEventListener('abort', handlerEvent);
-      xhr.addEventListener('error', handlerEvent);
-      xhr.addEventListener('load', handlerEvent);
-      xhr.addEventListener('progress', handlerEvent);
+      xhr.addEventListener('abort', onEvent);
+      xhr.addEventListener('error', onEvent);
+      xhr.addEventListener('load', onEvent);
+      xhr.addEventListener('progress', onEvent);
       //// show progress bar
       local._xhrProgressDisplay(true);
       return xhr;

File package.json

   "scripts": {
     "test": "echo \"Error: no test specified\" && exit 1"
   },
-  "version": "2013.03.24-03.03.50"
+  "version": "2013.03.24-05.01.30"
 }