-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
31 lines (29 loc) · 832 Bytes
/
app.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
var http = require("http");
var fs = require("fs");
var Slipper = require("./Slipper");
var g = new Slipper({i : 0});
g.addEvent("set", "i", function(value) {
console.log(g.toString());
console.log("visit#: " + value);
});
http.createServer(function(req, res) {
g.i++;
var loc = req.url == "/" ? "./index.html" : "." + req.url;
if ( loc.split(".").pop() == "html" ) {
var contentType = "text/html";
} else if ( loc.split(".").pop() == "js" ) {
var contentType = "text/javascript";
} else {
var contentType = "text/plain";
}
fs.readFile(loc, "utf-8", function(err, data) {
if ( err ) {
res.writeHead(404, {"Content-Type":"text/plain"});
res.end("Path: \"" + loc + "\";\n " + err);
return false;
}
res.writeHead(200, {"Content-Type":contentType});
res.end(data);
return true;
});
}).listen(3000);