Skip to content

Commit b5f7256

Browse files
committed
Copilot third commit
1 parent 27b41b7 commit b5f7256

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

comments.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Create web server
2+
// Load HTTP module
3+
const http = require("http");
4+
const fs = require("fs");
5+
const url = require("url");
6+
const path = require("path");
7+
const port = 3000;
8+
9+
const server = http.createServer((req, res) => {
10+
console.log(req.url);
11+
if (req.url === "/") {
12+
fs.readFile("./index.html", function (error, data) {
13+
res.writeHead(200, { "Content-Type": "text/html" });
14+
res.write(data);
15+
res.end();
16+
});
17+
} else if (req.url === "/comments") {
18+
fs.readFile("./comments.json", function (error, data) {
19+
res.writeHead(200, { "Content-Type": "application/json" });
20+
res.write(data);
21+
res.end();
22+
});
23+
} else if (req.url === "/comments.js") {
24+
fs.readFile("./comments.js", function (error, data) {
25+
res.writeHead(200, { "Content-Type": "text/javascript" });
26+
res.write(data);
27+
res.end();
28+
});
29+
} else {
30+
res.writeHead(404, { "Content-Type": "text/html" });
31+
res.write("<h1>Page not found</h1>");
32+
res.end();
33+
}
34+
});
35+
36+
server.listen(port, () => {
37+
console.log(`Server running at http://localhost:${port}/`);
38+
});

0 commit comments

Comments
 (0)