-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
58 lines (54 loc) · 2.24 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
var http = require('http');
var url = require('url');
var events = require('events');
var fs = require('fs');
http.createServer(function(request, response){
response.writeHead(200, { 'Content-Type': 'text/html' });
var myReadStream;
var datetime = new Date();
var days=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var day = "/" +days[datetime.getDay()].toLowerCase().trim();
if(request.url == "/" || request.url == "/favicon.ico"){
myReadStream = fs.createReadStream(__dirname + '/pages/home.html','utf8');
myReadStream.pipe(response);
}
else if(request.url == "/portfolio"){
myReadStream = fs.createReadStream(__dirname + '/pages/portfolio.html','utf8');
myReadStream.pipe(response);
}
else if(request.url == "/about"){
myReadStream = fs.createReadStream(__dirname + '/pages/about.html','utf8');
myReadStream.pipe(response);
}
else if(request.url == day){
response.write(`<html><head><style>div.centre {
width: 200px;
display: block;
background-color: #eaf1a9;
margin-left: auto;
margin-right: auto;
text-align: center;
}</style></head><body>`);
response.write(`<a href="/" style="background-color:rgb(238, 255, 0);color: black; padding: 8px 20px; text-decoration:none;
font-weight:bold;
border-radius:5px;
cursor:pointer; float:right; margin-right: 100px;"> Back</a>
<div class="centre">`+
" <p> Time: " +datetime.toLocaleTimeString()+"</p>"+
"</div>"
);
response.end('</body></html>');
}
else{
response.write('<html><head></head><body>');
response.write(`<a href="/" style="background-color:rgb(238, 255, 0);color: black; padding: 8px 20px; text-decoration:none;
font-weight:bold;
border-radius:5px;
cursor:pointer; float:right; margin-right: 100px;"> Back</a>
<div class="centre">`+
"<p> Not current day. Please go Back...!!</p>"+
"</div>");
response.end('</body></html>');
}
}).listen(8080);
console.log('Server is running at http://127.0.0.1:8080/ ');