-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
30 lines (25 loc) · 1005 Bytes
/
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
/* start of file ->*/
ls = __filename.lastIndexOf('/');
rs = __filename.lastIndexOf('\\');
__filename = __filename.substring((((ls >= 0)? ls + 1: 0) | ((rs >= 0)? rs + 1: 0)), __filename.length);
console.log('[' + __filename + ']' + ": starting");
exports.done = false;
/* start of file <- */
/* ----------------------------------------- */
function route(handle, pathname, response) {
console.log('[' + __filename + ']' + "{export}: About to route a request for " + pathname);
if (typeof handle[pathname] === 'function') {
handle[pathname](response);
} else {
console.log('[' + __filename + ']' + "{export}: No request handler found for " + pathname);
response.writeHead(404, { "Content-Type": "text/plain" });
response.write("404 Not found");
response.end();
}
}
exports.route = route;
/* ----------------------------------------- */
/*end of file ->*/
exports.done = true;
console.log('[' + __filename + ']' + ": done.");
/*end of file <-*/