-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrouter.js
More file actions
24 lines (23 loc) · 765 Bytes
/
router.js
File metadata and controls
24 lines (23 loc) · 765 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
// Deal with different URL's being hit
// @jfreeman
var fs = require('fs');
exports.route = function(mapping, path, response, postData, method){
var pathparts = path.split('/');
var shortpath = '/'+pathparts[1] + '_'+method;
if( path === '/') {
fs.readFile('index.html', function(err, data) {
response.writeHead(200, {"Content-Type":"text/html"});
response.write(data);
response.end();
});
}
else if (typeof mapping[shortpath] === 'function') {
mapping[shortpath](response, postData, pathparts);
}
else {
//error out
response.writeHead(404, {"Content-Type":"text/plain"});
response.write("404: Not Found");
response.end();
}
};