Skip to content

Commit ca8590e

Browse files
Copilot third commit
1 parent f28daf0 commit ca8590e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

comments.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// create web server
2+
// 1. Create a web server
3+
// 2. Create a route
4+
// 3. Create a response
5+
6+
// 1. Create a web server
7+
const http = require('http');
8+
const server = http.createServer();
9+
server.listen(3000);
10+
11+
// 2. Create a route
12+
server.on('request', (req, res) => {
13+
if (req.url === '/comments') {
14+
res.writeHead(200, { 'Content-Type': 'application/json' });
15+
res.write(JSON.stringify({ comments: [] }));
16+
res.end();
17+
}
18+
else {
19+
res.writeHead(404);
20+
res.end();
21+
}
22+
});
23+
// 3. Create a response
24+
// http://localhost:3000/comments
25+
// GET /comments
26+
// 200 OK
27+
// Content-Type: application/json
28+
// { "comments": [] }
29+
30+
// http://localhost:3000/unknown
31+
// GET /unknown
32+
// 404 Not Found

0 commit comments

Comments
 (0)