-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.js
38 lines (33 loc) · 1.67 KB
/
router.js
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
31
32
33
34
35
36
37
38
/************************************************************
* ROUTER.js *
*----------------------------------------------------------*
* AUTHOR: Christopher Webster *
* DATE: Oct. 3rd 2012 *
*----------------------------------------------------------*
* PURPOSE: *
* Responds to web requests by: *
* a) matching them to a route, and executing that route *
* b) responding with 404 - Not Found *
* *
*----------------------------------------------------------*
* NOTES: *
* none *
*----------------------------------------------------------*
* CHANGES: *
* DATE: *
* CHANGE: *
* **********************************************************/
var util = require('util');
function route(request, handle, pathname, response) {
util.log("About to route a request for " + pathname);
if (typeof handle[pathname] === 'function') {
handle[pathname](response, request);
}
else{
util.log("No request handler found for " + pathname);
response.writeHead(404, {"Content-Type": "text/plain"});
response.write("404 Not Found");
response.end();
}
}
exports.route = route;