upstream now appears to work just fine
[nodejs-repoproxy.git] / lib / router.js
index 71fddb1..8a7dca2 100644 (file)
@@ -6,7 +6,10 @@ var path = require("path");
 exports.routeRequest = function(req, res) {
        // first, unify the request
        var thisQuery = unifyRequest(req, res, function(unified) {
-               if(unified.exists) {
+               if(unified.requestFor == "/favicon.ico") {
+                       unified.b.writeHead(404, {"Content-Type": "text/plain"});
+                       unified.b.write("404 Not Found\n");
+               } else if(unified.exists) {
                        if(unified.isFile) {
                                cache.serviceFile(unified);
                        } else if(unified.isDirectory) {
@@ -42,18 +45,10 @@ function unifyRequest(req, res, callback, testing) {
        // create the full file path by spanning the cachedir
        unified.fullFilePath = (global.repoproxy.cacheDir + "/" + originalurl.pathname.replace(/^\/pub/, "")).replace(/\/+/g, "/");
        
-       // determine if the request is for a directory
-       if(unified.requestFor.match(/\/$/) != null) {
-               unified.isDirectoryRequest = true;
-               unified.fullPathDirName = unified.fullFilePath;
-       } else {
-               unified.isDirectoryRequest = false;
-               unified.fullPathDirName = path.dirname(unified.fullFilePath);
-       }
-       
        // determine the topPath, subpath etc.
        var spl = unified.requestFor.split("/");
        unified.topPath = spl[1];
+       unified.topFullPath = (global.repoproxy.cacheDir + "/" + spl[1]).replace(/\/+/g, "/");
        unified.subPath = "";
        if(spl.length > 2) {
                for(var i=2; i < spl.length; i++) {
@@ -64,6 +59,17 @@ function unifyRequest(req, res, callback, testing) {
                unified.subPath = null;
        }
        
+       // determine if the request is for a directory
+       if(unified.requestFor.match(/\/$/) != null) {
+               unified.isDirectoryRequest = true;
+               unified.fullPathDirName = unified.fullFilePath;
+               unified.subPathDirName = unified.subPath;
+       } else {
+               unified.isDirectoryRequest = false;
+               unified.fullPathDirName = path.dirname(unified.fullFilePath);
+               unified.subPathDirName = path.dirname(unified.subPath);
+       }
+       
        
        fs.stat(unified.fullFilePath, function(err, stats) {
                if(err == null) {