28 lines
762 B
JavaScript
28 lines
762 B
JavaScript
const http = require("http");
|
|
|
|
const PORT = 8080;
|
|
|
|
const server = http.createServer((req, res) => {
|
|
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: process.env[key] ?? "env not found",
|
|
}
|
|
: { 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");
|
|
}
|
|
});
|
|
|
|
server.listen(PORT, () => {
|
|
console.log(`Server running on port ${PORT}`);
|
|
});
|