-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (58 loc) · 1.89 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var port = process.env.PORT || 3000,
http = require('http'),
fs = require('fs');
var app = http.createServer(function (req, res) {
if (req.url.indexOf('/img') != -1) {
var filePath = req.url.split('/img')[1];
fs.readFile(__dirname + '/public/img' + filePath, function (err, data) {
if (err) {
res.writeHead(404, {'Content-Type': 'text/plain'});
res.write('Error 404: Resource not found.');
console.log(err);
} else {
res.writeHead(200, {'Content-Type': 'image/svg+xml'});
res.write(data);
}
res.end();
});
} else if (req.url.indexOf('/js') != -1) {
var filePath = req.url.split('/js')[1];
fs.readFile(__dirname + '/public/js' + filePath, function (err, data) {
if (err) {
res.writeHead(404, {'Content-Type': 'text/plain'});
res.write('Error 404: Resource not found.');
console.log(err);
} else {
res.writeHead(200, {'Content-Type': 'text/javascript'});
res.write(data);
}
res.end();
});
} else if(req.url.indexOf('/css') != -1) {
var filePath = req.url.split('/css')[1];
fs.readFile(__dirname + '/public/css' + filePath, function (err, data) {
if (err) {
res.writeHead(404, {'Content-Type': 'text/plain'});
res.write('Error 404: Resource not found.');
console.log(err);
} else {
res.writeHead(200, {'Content-Type': 'text/css'});
res.write(data);
}
res.end();
});
} else {
fs.readFile(__dirname + '/public/index.html', function (err, data) {
if (err) {
res.writeHead(404, {'Content-Type': 'text/plain'});
res.write('Error 404: Resource not found.');
console.log(err);
} else {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
}
res.end();
});
}
}).listen(port, '0.0.0.0');
module.exports = app;