Skip to content

Commit

Permalink
Copilot third commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nitheeshgovind committed May 25, 2024
1 parent f28daf0 commit ca8590e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions comments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// create web server
// 1. Create a web server
// 2. Create a route
// 3. Create a response

// 1. Create a web server
const http = require('http');
const server = http.createServer();
server.listen(3000);

// 2. Create a route
server.on('request', (req, res) => {
if (req.url === '/comments') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.write(JSON.stringify({ comments: [] }));
res.end();
}
else {
res.writeHead(404);
res.end();
}
});
// 3. Create a response
// http://localhost:3000/comments
// GET /comments
// 200 OK
// Content-Type: application/json
// { "comments": [] }

// http://localhost:3000/unknown
// GET /unknown
// 404 Not Found

0 comments on commit ca8590e

Please sign in to comment.