-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.js
More file actions
24 lines (19 loc) · 703 Bytes
/
Copy pathrouter.js
File metadata and controls
24 lines (19 loc) · 703 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var path = require("path");
function send404(response,pathname){
response.writeHead(404,{'Content-Type':'text/plain'});
response.write("Error 404: '"+pathname+"' no found!");
response.end();
}
function route(handle, pathname, response, request){
console.log("About to route a request for "+pathname);
//
if(pathname.split(".").length>1){
handle["/insert"](response,request,pathname.substring(0,pathname.length-1));
}else if(typeof handle[pathname]=='function'){
handle[pathname](response,request);
}else{
send404(response,pathname);
}
}
exports.send404=send404;
exports.route = route;