Homework 8 Completion

++ Homework 8 Files
+- Modified server.js
This commit is contained in:
Charles Descamps 2023-04-10 21:37:40 -07:00
parent 60087976ca
commit 0f2b3d0ef8
3 changed files with 150 additions and 2 deletions

View file

@ -10,6 +10,23 @@ server.get('/do_a_random', (req, res) => {
res.send(`Your number is: ${Math.floor(Math.random() * 100) + 1}`)
})
server.post("/cs212/homework/8/index.html", (req, res) => {
// Retrieve form data from request body
ingredientOneInput = req.body.ingredientOne;
ingredientTwoInput = req.body.ingredientTwo;
ingredientThreeInput = req.body.ingredientThree;
ingredientFourInput = req.body.ingredientFour;
ingredientFiveInput = req.body.ingredientFive;
ingredientSixInput = req.body.ingredientSix;
ingredientSevenInput = req.body.ingredientSeven;
// Create mad lib string
madLib = `A throw together soup consisting of: One cup of ${ingredientOneInput}, Five cups of ${ingredientTwoInput}, Two ${ingredientThreeInput}, 1/2 cup of ${ingredientFourInput}, One large ${ingredientFiveInput}, 1/4 pound of ${ingredientSixInput}, and ${ingredientSevenInput} to taste`;
// Send mad lib as response
res.send(madLib);
});
// Setup static page serving for all the pages in "public"
const publicServedFilesPath = path.join(__dirname, 'public')
@ -19,9 +36,9 @@ server.use(express.static(publicServedFilesPath))
// The server uses port 80 by default unless you start it with the extra
// command line argument 'local' like this:
// node server.js local
let port = 80
let port = 8191
if (process.argv[2] === 'local') {
port = 8080
port = 80
}
server.listen(port, () => console.log('Ready on localhost!'))