/
server.js
138 lines (132 loc) · 4.34 KB
/
server.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env node
const http = require('http');
const fs = require('fs')
const url = require('url');
const querystring = require('querystring');
const figlet = require('figlet')
// const hostname = '127.0.0.1'
const PORT = 8000
const server = http.createServer((req, res) => {
const page = url.parse(req.url).pathname;
const params = querystring.parse(url.parse(req.url).query);
console.log(page);
if (page == '/') {
fs.readFile('index.html', function(err, data) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
res.end();
});
}
else if (page == '/images/aquarius.png'){
fs.readFile('./images/aquarius.png', function(err, data) {
res.writeHead(200, {'Content-Type':'image/png'});
res.write(data);
res.end();
})
}else if (page == '/images/aries.png'){
fs.readFile('./images/aries.png', function(err, data) {
res.writeHead(200, {'Content-Type':'image/png'});
res.write(data);
res.end();
})
}else if (page == '/images/cancer.png'){
fs.readFile('./images/cancer.png', function(err, data) {
res.writeHead(200, {'Content-Type':'image/png'});
res.write(data);
res.end();
})
}else if (page == '/images/capricorn.png'){
fs.readFile('./images/capricorn.png', function(err, data) {
res.writeHead(200, {'Content-Type':'image/png'});
res.write(data);
res.end();
})
}else if (page == '/images/gemini.png'){
fs.readFile('./images/gemini.png', function(err, data) {
res.writeHead(200, {'Content-Type':'image/png'});
res.write(data);
res.end();
})
}else if (page == '/images/leo.png'){
fs.readFile('./images/leo.png', function(err, data) {
res.writeHead(200, {'Content-Type':'image/png'});
res.write(data);
res.end();
})
}else if (page == '/images/libra.png'){
fs.readFile('./images/libra.png', function(err, data) {
res.writeHead(200, {'Content-Type':'image/png'});
res.write(data);
res.end();
})
}else if (page == '/images/pisces.png'){
fs.readFile('./images/pisces.png', function(err, data) {
res.writeHead(200, {'Content-Type':'image/png'});
res.write(data);
res.end();
})
}else if (page == '/images/sagittarius.png'){
fs.readFile('./images/sagittarius.png', function(err, data) {
res.writeHead(200, {'Content-Type':'image/png'});
res.write(data);
res.end();
})
}else if (page == '/images/scorpio.png'){
fs.readFile('./images/scorpio.png', function(err, data) {
res.writeHead(200, {'Content-Type':'image/png'});
res.write(data);
res.end();
})
}else if (page == '/images/taurus.png'){
fs.readFile('./images/taurus.png', function(err, data) {
res.writeHead(200, {'Content-Type':'image/png'});
res.write(data);
res.end();
})
}else if (page == '/images/virgo.png'){
fs.readFile('./images/virgo.png', function(err, data) {
res.writeHead(200, {'Content-Type':'image/png'});
res.write(data);
res.end();
})
}else if (page == '/images/Zodiac3.jpg'){
fs.readFile('./images/Zodiac3.jpg', function(err, data) {
res.writeHead(200, {'Content-Type':'image/png'});
res.write(data);
res.end();
})
}else if (page == '/images/Zodiac1.jpg'){
fs.readFile('./images/Zodiac1.jpg', function(err, data) {
res.writeHead(200, {'Content-Type':'image/png'});
res.write(data);
res.end();
})
}else if (page == '/css/style.css'){
fs.readFile('css/style.css', function(err, data) {
res.write(data);
res.end();
});
}else if (page == '/css/reset.css'){
fs.readFile('css/style.css', function(err, data) {
res.write(data);
res.end();
});
}else if (page == '/js/main.js'){
fs.readFile('js/main.js', function(err, data) {
res.writeHead(200, {'Content-Type': 'text/javascript'});
res.write(data);
res.end();
});
}else{
figlet('404!!', function(err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
res.write(data);
res.end();
});
}
});
server.listen(process.env.PORT || PORT);