Skip to content

Instantly share code, notes, and snippets.

@gmosx
Created June 24, 2010 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmosx/451564 to your computer and use it in GitHub Desktop.
Save gmosx/451564 to your computer and use it in GitHub Desktop.
/**
* 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