X-Git-Url: http://git.pjr.cc/?p=nodejs-repoproxy.git;a=blobdiff_plain;f=lib%2Frouter.js;fp=lib%2Frouter.js;h=fcf697c47fac7c10dd8ed77d07e53f4d3f2b8572;hp=626eb5dd35703f7c74ea0de328dffe908a08f855;hb=8b95cb4f106b906a362babc2c21b18d57c7a4748;hpb=3fa5e831263792a76c9430b9d86e353901bc4477 diff --git a/lib/router.js b/lib/router.js index 626eb5d..fcf697c 100644 --- a/lib/router.js +++ b/lib/router.js @@ -5,7 +5,9 @@ var path = require("path"); exports.routeRequest = function(req, res) { // first, unify the request + console.log("request: ", req.url); var thisQuery = unifyRequest(req, res, function(unified) { + console.log("unified request is ", unified); if(unified.requestFor == "/favicon.ico") { unified.b.writeHead(404, {"Content-Type": "text/plain"}); unified.b.write("404 Not Found\n"); @@ -20,14 +22,20 @@ exports.routeRequest = function(req, res) { console.log("ERROR: something went majorly wrong with something, ", unified); } } 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); + // it doesnt exist yet, so we send it to the cache service if it matches an upstream service + if(typeof global.repoproxy.repo[unified.topPath] != "undefined") { + console.log("file doesnt exist, upstream we go: ", unified); + cache.upstreamRequest(unified); + } else { + unified.b.writeHead(404, {"Content-Type": "text/plain"}); + unified.b.write("404 Not Found\n"); + unified.b.end(); + } } }); } -function unifyRequest(req, res, callback, testing) { +function unifyRequest(req, res, callback) { var unified = new Object(); var originalurl = url.parse(req.url); @@ -76,24 +84,24 @@ function unifyRequest(req, res, callback, testing) { //send a 302 and call it a day res.writeHead("302", { 'Location': unified.originalReq+"/" }); res.end(); - - // TODO: remove this after testing - if(testing) callback(null); - return 302; } if(stats.isDirectory()) { unified.isDirectory = true; unified.isFile = false; + unified.fileSize = null; } else if(stats.isFile()) { unified.isDirectory = false; - unified.isFile = true; + unified.isFile = true; + unified.fileSize = stats["size"]; } else { unified.isDirectory = false; unified.isFile = false; + unified.fileSize = null; } } else { unified.exists = false; + unified.fileSize = null; } callback(unified);