-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (27 loc) · 1.05 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const express = require("express");
const app = express();
const cors = require("cors");
app.use(cors());
app.use(express.json());
let gumballs = [
{ message: "You've got this! Don't give up!", color: "#fd8a08" },
{ message: "You're doing great! Keep going!", color: "#c747eb" },
{ message: "You're amazing! Keep it up!", color: "#1ee6a3" },
{ message: "Believe in yourself! You can do it!", color: "#ff5733" },
{ message: "Stay positive and keep coding!", color: "#00bfff" },
{ message: "You're a coding superstar!", color: "#ff00ff" },
];
app.post("/add-gumball", (req, res) => {
const { message, color } = req.body;
gumballs.push({ message, color });
res.send("Gumball added...");
console.log("Gumball added:", message, "Color:", color);
});
app.get("/random-gumball", (req, res) => {
let randomIndex = Math.floor(Math.random() * gumballs.length);
let randomGumball = gumballs[randomIndex];
res.send({ message: randomGumball.message, color: randomGumball.color });
});
app.listen(3000, () => {
console.log("Server started on port 3000");
});