-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (29 loc) · 766 Bytes
/
Copy pathserver.js
File metadata and controls
31 lines (29 loc) · 766 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
var app = require('http').createServer(handler),
fs = require('fs');
var port = Number(process.env.PORT || 5000);
app.listen(port, function() {
console.log("Listening on " + port);
});
function handler (req, res) {
if(req.url === "/"){
fs.readFile(__dirname + '/www/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
else{
fs.readFile(__dirname +"/www"+ req.url, function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading ' +req.url);
}
res.writeHead(200);
res.end(data);
});
}
}