diff --git a/app.js b/app.js index f26fab1..c533b74 100644 --- a/app.js +++ b/app.js @@ -3,9 +3,16 @@ const http = require("http"); const PORT = 8080; const server = http.createServer((req, res) => { - if (req.method === "GET" && req.url === "/") { - res.writeHead(200, { "Content-Type": "text/plain" }); - res.end("Now push the code disconnected as I shown o"); + const parsedUrl = new URL(req.url, `http://${req.headers.host}`); + + if (req.method === "GET" && parsedUrl.pathname === "/") { + const key = parsedUrl.searchParams.get("key"); + const response = key + ? { message: "added to the response", value: key } + : { message: "key query param not found" }; + + res.writeHead(200, { "Content-Type": "application/json" }); + res.end(JSON.stringify(response)); } else { res.writeHead(404, { "Content-Type": "text/plain" }); res.end("Not Found");