Oh hi,
- -Tell me your hopes and dreams:
- - - -diff --git a/public/client.js b/public/client.js deleted file mode 100644 index 3b00a1e..0000000 --- a/public/client.js +++ /dev/null @@ -1,42 +0,0 @@ -// client-side js -// run by the browser each time your view template is loaded - -console.log("hello world :o"); - -// our default array of dreams -const dreams = [ - "Find and count some sheep", - "Climb a really tall mountain", - "Wash the dishes" -]; - -// define variables that reference elements on our page -const dreamsList = document.getElementById("dreams"); -const dreamsForm = document.forms[0]; -const dreamInput = dreamsForm.elements["dream"]; - -// a helper function that creates a list item for a given dream -const appendNewDream = function(dream) { - const newListItem = document.createElement("li"); - newListItem.innerHTML = dream; - dreamsList.appendChild(newListItem); -}; - -// iterate through every dream and add it to our page -dreams.forEach(function(dream) { - appendNewDream(dream); -}); - -// listen for the form to be submitted and add a new dream when it is -dreamsForm.onsubmit = function(event) { - // stop our form submission from refreshing the page - event.preventDefault(); - - // get dream value and add it to the list - dreams.push(dreamInput.value); - appendNewDream(dreamInput.value); - - // reset form - dreamInput.value = ""; - dreamInput.focus(); -}; diff --git a/public/style.css b/public/style.css deleted file mode 100644 index 3641cab..0000000 --- a/public/style.css +++ /dev/null @@ -1,71 +0,0 @@ -/* styles */ -/* called by your view template */ - -* { - box-sizing: border-box; -} - -body { - font-family: helvetica, arial, sans-serif; - margin: 2em; -} - -h1 { - font-style: italic; - color: #373fff; -} - -.bold { - font-weight: bold; -} - -p { - max-width: 600px; -} - -form { - margin-bottom: 25px; - padding: 15px; - background-color: cyan; - display: inline-block; - width: 100%; - max-width: 340px; - border-radius: 3px; -} - -input { - display: block; - margin-bottom: 10px; - padding: 5px; - width: 100%; - border: 1px solid lightgrey; - border-radius: 3px; - font-size: 16px; -} - -button { - font-size: 16px; - border-radius: 3px; - background-color: lightgrey; - border: 1px solid grey; - box-shadow: 2px 2px teal; - cursor: pointer; -} - -button:hover { - background-color: yellow; -} - -button:active { - box-shadow: none; -} - -li { - margin-bottom: 5px; -} - -footer { - margin-top: 50px; - padding-top: 25px; - border-top: 1px solid lightgrey; -} diff --git a/server.js b/server.js index 0b9ab3a..e6ac12d 100644 --- a/server.js +++ b/server.js @@ -36,29 +36,18 @@ sequelize.authenticate() } }); - setup(); + Readings.sync(); }) .catch(function (err) { console.log('Unable to connect to the database: ', err); }); -// populate table with default users -function setup(){ - Readings.sync({force: true}).then(function() { - Readings.create({ timestamp: new Date(), reading: 30 }); - console.log(Readings); - }); -} - // we've started you off with Express, // but feel free to use whatever libs or frameworks you'd like through `package.json`. -// http://expressjs.com/en/starter/static-files.html -app.use(express.static("public")); - // http://expressjs.com/en/starter/basic-routing.html -app.get("/", function(request, response) { - response.sendFile(__dirname + "/views/index.html"); +app.get("/", function(req, res) { + res.sendFile(__dirname + "/views/index.html"); }); app.get("/data", function (request, response) { @@ -71,9 +60,13 @@ app.get("/data", function (request, response) { }); }); -app.get("/newreading", function(request, response) { - Readings.create({ timestamp: new Date(), reading: 30 }); - response.status(200).send('GlitchApp Success').end(); +// Handle requests to post a new reading +app.get('/newreading', (req, res) => { + // Filter out requests that don't include the secret key, or don't contain the required data + if (req.query.s != process.env.SECRET || !RegExp('^\\d*$').test(req.query.v)) return res.status(400).send('Bad Request').end(); + + Readings.create({ timestamp: new Date(), reading: req.query.v }); + res.status(200).send('Reading received: ' + req.query.v).end(); }); // listen for requests :) diff --git a/views/index.html b/views/index.html index 6489186..a874895 100644 --- a/views/index.html +++ b/views/index.html @@ -1,58 +1,178 @@ - - - - - - - - - - + -
-Oh hi,
- -Tell me your hopes and dreams:
- - - -