44 lines
1.6 KiB
JavaScript
44 lines
1.6 KiB
JavaScript
const express = require('express')
|
|
const logger = require('morgan')
|
|
const path = require('path')
|
|
const server = express()
|
|
server.use(express.urlencoded({'extended': true}))
|
|
server.use(logger('dev'))
|
|
|
|
// Routes
|
|
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')
|
|
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 = 8191
|
|
if (process.argv[2] === 'local') {
|
|
port = 80
|
|
}
|
|
|
|
server.listen(port, () => console.log('Ready on localhost!'))
|