-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.js
More file actions
30 lines (26 loc) · 980 Bytes
/
router.js
File metadata and controls
30 lines (26 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* Created by rbwilliams on 27/11/2015.
*/
function route(handle, pathname,response,request,debug) {
console.log("Routing Request for: " + pathname);
if (pathname.indexOf(".css") >= 0 || pathname.indexOf(".less") >= 0){
handle["css"](response, pathname);
} else if (pathname.indexOf(".js") >= 0){
handle["js"](response, pathname);
} else if (pathname.indexOf(".html") >= 0 ){
handle["html"](response, pathname);
} else if (pathname.indexOf(".ico") >= 0 || pathname.indexOf("png") >= 0 || pathname.indexOf("jpg") >= 0 ){
handle["images"](response, pathname);
} else if (pathname == "/") {
handle["html"](response, pathname);
}
else {
if(debug == true){
console.log("No request handler found for " + pathname);
}
response.writeHead(404, {"Content-Type": "text/plain"});
response.write("404 Not found");
response.end();
}
}
exports.route = route;