trying to find out whats causing an occasional crash
[nodejs-repoproxy.git] / lib / router.js
index 8a7dca2..626eb5d 100644 (file)
@@ -10,7 +10,9 @@ exports.routeRequest = function(req, res) {
                        unified.b.writeHead(404, {"Content-Type": "text/plain"});
                        unified.b.write("404 Not Found\n");
                } else if(unified.exists) {
-                       if(unified.isFile) {
+                       if(typeof global.repoproxy.downloads[unified.fullFilePath] != "undefined" && global.repoproxy.downloads[unified.fullFilePath] == 1) {
+                               cache.upstreamRequest(unified);
+                       } else if(unified.isFile) {
                                cache.serviceFile(unified);
                        } else if(unified.isDirectory) {
                                cache.serviceDirectory(unified);
@@ -20,11 +22,7 @@ exports.routeRequest = function(req, res) {
                } else {
                        // it doesnt exist yet, so we send it to the cache service
                        console.log("file doesnt exist, upstream we go: ", unified);
-                       cache.upstreamRequest(unified, function(err) {
-                               if(err == null) {
-                                       cache.watchAndService(unfied);
-                               } // if upstream sends anything other then a 200, cache.upstreamRequest will handle it (i.e. 302, 404, etc)
-                       });
+                       cache.upstreamRequest(unified);
                }
        });
 }