From a5ce448918a990849f44a2916ab1f36c7b27e23d Mon Sep 17 00:00:00 2001 From: "Glitch (hello-express)" Date: Fri, 23 Oct 2020 19:58:27 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=95=B0=F0=9F=91=9E=20Checkpoint=20./publi?= =?UTF-8?q?c/script.js:617503/4050=20./server.js:617503/359?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/script.js | 34 ++-------------------------------- server.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 34 deletions(-) diff --git a/public/script.js b/public/script.js index 9790ab6..36c9247 100644 --- a/public/script.js +++ b/public/script.js @@ -3,39 +3,9 @@ console.log("hello world :o"); -// define variables that reference elements on our page -const dreamsList = document.getElementById("dreams"); -const dreamsForm = document.querySelector("form"); - -// a helper function that creates a list item for a given dream -function appendNewDream(dream) { - const newListItem = document.createElement("li"); - newListItem.innerText = dream; - dreamsList.appendChild(newListItem); -} - // fetch the initial list of dreams -fetch("/dreams") +fetch("/api/flavors") .then(response => response.json()) // parse the JSON from the server .then(dreams => { - // remove the loading text - dreamsList.firstElementChild.remove(); - - // iterate through every dream and add it to our page - dreams.forEach(appendNewDream); - - // listen for the form to be submitted and add a new dream when it is - dreamsForm.addEventListener("submit", event => { - // stop our form submission from refreshing the page - event.preventDefault(); - - // get dream value and add it to the list - let newDream = dreamsForm.elements.dream.value; - dreams.push(newDream); - appendNewDream(newDream); - - // reset form - dreamsForm.reset(); - dreamsForm.elements.dream.focus(); - }); + return []; }); diff --git a/server.js b/server.js index 87b8721..40196d6 100644 --- a/server.js +++ b/server.js @@ -11,12 +11,18 @@ fastify.register(require('fastify-static'), { prefix: '/', // optional: default '/' }) -// Declare a route +// Our home page route, this pulls from public/index.html +// but you don't have to send a html, or even have a webpage! fastify.get("/", function(request, reply) { return reply.sendFile('index.html') }); -// Run the server! +// Our API route, fastify automatically turns it to JSON +fastify.get("/api/flavors", function(request, reply) { + reply.send({ hello: 'world' }) +}); + +// Run the server and report out to the logs fastify.listen(process.env.PORT, function(err, address) { if (err) { fastify.log.error(err);