-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
60 lines (49 loc) · 1.49 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// const http = require("http");
// const server = http.createServer(function (req, res) {
// console.log(`user visited ${req.url}`);
// res.end("hello");
// });
// console.log("listening on http://localhost:3000");
// server.listen(3000);
// const express = require("express");
// const app = express();
// app.get("/", function (req, res) {
// res.end("welcome to my site");
// })
// app.get("/complement", function (req, res) {
// res.end("you look nice today");
// })
// app.listen(3000);
// console.log("listening on http://localhost:3000");
// console.log("dasdsa");
const express = require("express");
const path = require("path");
const complements = [
"You like nice today",
"That dress looks nice on you",
"Have you been working out?",
"You can do hard things",
"You've gotten far in this course. You're really smart",
"You're programming! How cool is that?",
"I'm really proud of you",
"You made this",
"You've learned a lot of things, and that's pretty hard to do"
];
function getRandomComplement() {
const randomIndex = Math.floor(Math.random() * complements.length);
return complements[randomIndex];
}
const app = express();
app.get("/", function(req, res) {
res.sendFile(path.join(__dirname, "index.html"));
});
app.get("/complement", function(req, res) {
res
.json({
complement: getRandomComplement()
})
.end();
});
app.use("/public", express.static("./public"));
app.listen(3000);
console.log("listening on http://localhost:3000");