-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-http.js
38 lines (36 loc) · 1.21 KB
/
app-http.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
var http = require('http');
var fs = require('fs');
http.createServer(function (req, res) {
if(req.url==='/'){
fs.readFile(__dirname + '/public/index.html', function (err, data) {
if (err) console.log(err);
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
res.end();
});
}
else if(req.url.indexOf('.js') != -1){
fs.readFile(__dirname + req.url, function (err, data) {
if (err) console.log(err);
res.writeHead(200, {'Content-Type': 'text/javascript'});
res.write(data);
res.end();
});
}
else if(req.url.indexOf('.css') != -1){
fs.readFile(__dirname + req.url, function (err, data) {
if (err) console.log(err);
res.writeHead(200, {'Content-Type': 'text/css'});
res.write(data);
res.end();
});
}
else if(req.url.indexOf('.png') != -1 || req.url.indexOf('.jpg') != -1){
fs.readFile(__dirname + req.url, function (err, data) {
if (err) console.log(err);
res.writeHead(200, {'Content-Type': 'image/jpeg'});
res.write(data);
res.end();
});
}
}).listen(8000);