Created
June 24, 2010 15:11
-
-
Save gmosx/451564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Map the request to different JSGI apps according to the URI. | |
* TODO: handle host. | |
*/ | |
exports.URIMap = function (map) { | |
var mapping = [], | |
defapp = map["*"]; | |
for (var uri in map) { | |
if (uri != "*") { | |
mapping.push([uri, map[uri]]); | |
} | |
} | |
return function (env) { | |
for (var i = 0; i < mapping.length; i++) { | |
var path = mapping[i][0]; | |
if (env.scriptName.slice(0, path.length) == path) { | |
return mapping[i][1](env); | |
} | |
} | |
return defapp(env); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment