-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.js
More file actions
25 lines (20 loc) · 698 Bytes
/
Copy pathrouter.js
File metadata and controls
25 lines (20 loc) · 698 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
/*
Call the right method to deal with request sent by user
and uses response object to write the page
*/
function route(handle, pathname, response, request) {
console.log("About to route a request for "+pathname);
//Test if the method defined on array handle is really a method.
//If yes call it and send response object as a parameter
//Otherwise return a 404 error
if (typeof handle[pathname] === 'function') {
handle[pathname](response, request);
}
else {
console.log("No request handler found for "+pathname);
response.writeHead(404, {"Content-type": "text/plain"});
response.write("404 Page not found");
response.end();
}
}
exports.route = route;