/* Objective: A simple webpage with an option that asks a user for their favourite color.
* Set that color as the background color of the webpage using a cookie. */
const express = require("express");
const app = express();
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/", (request, response) => {
const html = `
Background Color
Change the background color of the page
`;
response.status(200).send(html);
});
app.post("/", (request, response) => {
console.log(request.body);
response.cookie("background_color", request.body.background_color);
response.status(200).redirect("/result");
});
app.get("/result", (request, response) => {
const html = `
Background Color
Background color set through cookie successfully.
Set Background Color
`;
response.status(200).send(html);
});
app.listen(3000, () => console.log("Application listening at 3000..."));