Skip to content

Instantly share code, notes, and snippets.

@dmachi
Created September 29, 2010 16:24
Show Gist options
  • Select an option

  • Save dmachi/603050 to your computer and use it in GitHub Desktop.

Select an option

Save dmachi/603050 to your computer and use it in GitHub Desktop.
exports.urlMap = function(map, nextApp){
return function(request){
for (var i = 0; i<map.length; i++){
var match = map[i][0];
var ctor = map[i][1];
var returnRequest = map[i][2];
if (request.pathInfo.match(match)){
print("found match:", match);
var res = ctor(request, match);
if (res && returnRequest) return res;
return nextApp(request);
}
}
return nextApp(request);
}
}
exports.rewrite = function(replacement){
return function(request, match ){
request.pathInfo=request.pathInfo.replace(match, replacement);
}
}
exports.redirect = function(replacement){
var redirector = require("jack/redirect").Redirect(replacement);
return function(request){
return redirector(request);
}
}
var urlConf = [
[/^\/$/, rewrite("/blog/test")],
[/redir$/, redirect("/blog/test"), true]
];
var nodes = multiNode.listen({port: settings.port || 8080, nodes: settings.processes || 1},
require( "http" ).createServer(
require("jsgi-node").Listener(
// uncomment this to enable compression with node-compress
//require("pintura/jsgi/compress").Compress(
require("commonjs-utils/urlmap").urlMap(urlConf,
require("pintura/jsgi/cascade").Cascade([
// cascade from static to pintura REST handling
// the main place for static files accessible from the web
Static({urls:[""], root: "public", directoryListing: true}),
Static({urls:["/explorer"], root: require("nodules").getCachePath("persevere-client/") + "/explorer"}),
// this will provide access to the server side JS libraries from the client
require("transporter/jsgi/transporter").Transporter({
loader: require("nodules").forEngine("browser").useLocal().getModuleSource}),
// main pintura app
function(request){
return pinturaApp(request);
}
])
)
//)
)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment