-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
37 lines (32 loc) · 1.45 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
// Import the 'http' and 'fs' modules
var http = require("http")
var fs = require("fs")
// Create an HTTP server
var server = http.createServer(function (req,res){
console.log("hi boss", req.url) // Log the incoming request URL
// Check the requested URL and handle accordingly
if(req.url === "/me" || req.url === "/"){
// If the URL is '/me' or '/' serve 'me.html'
res.writeHead(200, {"content-Type":'text/html'});
fs.createReadStream(__dirname + "/me.html").pipe(res)
}else if(req.url === "/social" || req.url === "/"){
// If the URL is '/social', serve 'social.html
res.writeHead(200, {"contnt-Type":'text/html'});
fs.createReadStream(__dirname + "/social.html").pipe(res);
}else if(req.url === "/span" || req.url === "/"){
// If the URL is '/span', serve 'span.html
res.writeHead(200,{"content-Type": 'text/html'});
fs.createReadStream(__dirname + '/span.html').pipe(res);
}else {
// If the URL doesn't match any of the above, serve '404.html'
res.writeHead(404, {"content-Type": 'text/html'});
fs.createReadStream(__dirname + '/404.html').pipe(res);
}
});
// Set the server to listen on a specified port (default is 8080)
var PORT = process.env.PORT || 8080
server.listen(PORT, function(){
return console.log(`Listening on PORT ${PORT}`);
});
// Log a message to the console
console.log("Creative developer");