-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomServer2.js
More file actions
31 lines (27 loc) · 806 Bytes
/
customServer2.js
File metadata and controls
31 lines (27 loc) · 806 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
const http = require('http');
const fs = require('fs');
const host= "127.0.0.1";
const port =80;
const clock = fs.readFileSync("testFiles/index.html","utf-8");
const index= fs.readFileSync("testFiles/positionforserver.html","utf-8");
const server = http.createServer((req,res)=>{
url=req.url;
res.statusCode=200;
res.setHeader("Content-type","text/html");
if(url == '/'){
res.end(index);
}
else if(url == '/dash'){
fs.readFile("testFiles/boxforserver.html","utf-8",(err,data)=>res.end(data));
}
else if(url == '/clock'){
res.end(clock);
}
else{
res.statusCode = 404;
res.end("<h1>404 not found</h1>");
}
})
server.listen(port,host,()=>{
console.log(`Server running at http://${hostname}:${port}/`);
})