-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathback.js
More file actions
37 lines (33 loc) · 952 Bytes
/
back.js
File metadata and controls
37 lines (33 loc) · 952 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
32
33
34
35
36
37
const http = require('http');
const fs = require('fs');
const hostname = '127.0.0.1';
const port = 3000;
const home = fs.readFileSync('index.html')
const about = fs.readFileSync('./about.html')
const firstaid = fs.readFileSync('./firstaid.html')
const ambulance = fs.readFileSync('./ambulance.html')
const server = http.createServer((req, res)=>{
console.log(req.url);
url = req.url;
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
if(url == '/'){
res.end(home);
}
else if(url == '/about'){
res.end(about);
}
else if(url == '/firstaid'){
res.end(firstaid);
}
else if(url == '/ambulance'){
res.end(ambulance);
}
else{
res.statusCode = 404;
res.end("<h1>404 not found</h1>");
}
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});