-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
41 lines (28 loc) · 715 Bytes
/
app.js
File metadata and controls
41 lines (28 loc) · 715 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
26
27
28
29
30
31
32
33
34
35
36
37
var server,
ip = "127.0.0.1",
port = 5000,
http = require("http"),
url = require("url");
var fs = require("fs"),
filePath,
encode = "utf8";
var path;
server = http.createServer(function (req, res) {
path = url.parse(req.url);
filePath = "." + path.pathname + ".html";
console.log(filePath);
fs.readFile(filePath, encode, function(err, file) {
if (err) {
console.log("error");
res.writeHead(200, {'Content-Type':'text/plain'});
res.write(filePath);
res.end();
return;
}
res.writeHead(200, {'Content-Type':'text/html'});
res.write(file);
res.end();
});
});
server.listen(port, ip);
console.log("Server running at http://" + ip + ":" + port);