Skip to content

Commit

Permalink
Implements tests
Browse files Browse the repository at this point in the history
  • Loading branch information
silentrob committed Feb 7, 2014
1 parent d54466e commit 9ad6b53
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ exports.notMultihostURL = function(req, rsp, next){
}
}

var reservedDomains = ["harp.io", "harpdev.io", "harpapp.io"];
exports.index = function(dirPath){
return function(req, rsp, next){
var host = req.headers.host;
Expand All @@ -54,28 +55,33 @@ exports.index = function(dirPath){

files.forEach(function(file){
var local = file.split('.');

var appPart = local.join("_");

if (local.length > 2) {
var domain = local.slice(Math.max(local.length - 2, 1)).join(".");
if (reservedDomains.indexOf(domain) != -1) {
appPart = local[0];
}
}

// DOT files are ignored.
if (file[0] !== ".") {
projects.push({
"name" : file,
"localUrl" : 'http://' + appPart + "." + host,
"localPath" : path.resolve(dirPath, file)
});

}
});

poly.render("index.jade", { pkg: pkg, projects: projects, layout: "_layout.jade" }, function(error, body){
rsp.end(body)
});

})
} else {
next();
}

}
}

Expand All @@ -87,11 +93,18 @@ exports.hostProjectFinder = function(dirPath){

fs.readdir(dirPath, function(err, files){
var appPart = hostname.split(".")[0];

files.forEach(function(file){
var fp = file.split('.');
var filePart = fp.join("_");

var filePart;
// Check against Reserved Domains first.
if (fp.length > 2) {
var domain = fp.slice(Math.max(fp.length - 2, 1)).join(".");
if (reservedDomains.indexOf(domain) != -1) {
fp = fp.slice(0, Math.max(fp.length - 2))
}
}

filePart = fp.join("_");
if (appPart == filePart) {
matches.push(file);
}
Expand All @@ -115,7 +128,6 @@ exports.regProjectFinder = function(projectPath){
}
}


/**
* Fallbacks
*
Expand Down

0 comments on commit 9ad6b53

Please sign in to comment.