-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (23 loc) · 838 Bytes
/
Copy pathserver.js
File metadata and controls
27 lines (23 loc) · 838 Bytes
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
const express = require("express");
const app = express();
const PORT = 8000;
const philosophers = {
socrates: { age: 71, birthName: "Socrates", birthLocation: "Athens" },
plato: { age: 80, birthName: "Plato", birthLocation: "Athens" },
aristotle: { age: 62, birthName: "Aristotel", birthLocation: "Stagira" },
unknown: { age: 00, birthName: "unknown", birthLocation: "unknown" },
};
app.get("/", (req, res) => {
res.sendFile(__dirname + "/index.html");
});
app.get("/api/:philosopherName", (req, res) => {
const philosophersName = req.params.philosopherName.toLowerCase();
if (philosophers[philosophersName]) {
res.json(philosophers[philosophersName]);
} else {
res.json(philosophers["unknown"]);
}
});
app.listen(PORT, () => {
console.log(`The server is running on ${PORT}! You better go cach it!`);
});