-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (27 loc) · 1.04 KB
/
Copy pathapp.js
File metadata and controls
30 lines (27 loc) · 1.04 KB
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
var http = require('http');
var url = require('url');
var fs = require("fs");
var path = require("path");
var server = http.createServer(function (request, response) {
var pathname = url.parse(request.url).pathname;
var realPath = "client" + pathname;
path.exists(realPath, function (exists) {
if (!exists) {
response.writeHead(404, {'Content-Type': 'text/plain'});
response.write("This request URL " + pathname + " was not found on this server.");
response.end();
} else {
fs.readFile(realPath, "binary", function(err, file) {
if (err) {
response.writeHead(500, {'Content-Type': 'text/plain'});
response.end(err);
} else {
response.writeHead(200, {'Content-Type': 'text/html'});
response.write(file, "binary");
response.end();
}
});
}
});
}).listen(55555);
console.log('Server running at http://127.0.0.1:55555/');