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");
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);
//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);