import http from "http"; const host = '127.0.0.1'; const port = 8000; const user = JSON.stringify({ name: "Joe User", }); const stickers = { "88ae126f-b19a-4287-abe0-a8f5ac763cb7": { backgroundColor: "#000088", layout: "layout1", message1: "I am an activist!", }, } const requestListener = function (req, res) { res.setHeader("Content-Type", "application/json"); const urlParts = req.url.split("/"); console.log(urlParts); switch (urlParts[1]) { case "login": res.writeHead(200); res.end(user); break; case "sticker": if (!(urlParts[2] in stickers)) { res.writeHead(404); res.end('not found') break; } res.writeHead(200); const sticker = stickers[urlParts[2]]; const response = JSON.stringify(sticker); res.end(response); break; default: res.writeHead(200); res.end(JSON.stringify({nothing: 'here'})); } }; const server = http.createServer(requestListener); server.listen(port, host, () => { console.log(`Server is running on http://${host}:${port}`); });