-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
37 lines (30 loc) · 911 Bytes
/
app.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
const express = require('express');
const nofServers = 4;
const phoneStates = [];
const logPhoneState = () => {
console.clear();
console.log("-------------------------");
phoneStates.forEach(phoneState => {
console.log(` ${phoneState.name}: Contacts: ${phoneState.contacts.length}`);
console.dir(phoneState.contacts.map((contact) => `${contact.FirstName} ${contact.LastName}` ));
});
console.log("-------------------------");
}
for (let i = 0; i < nofServers; i++) {
phoneStates.push({
name: "Phone " + i,
contacts: []
});
const app = express();
app.use(express.json());
const port = 3000 + i;
app.get('/', (req, res) => {
res.send(phoneStates[i]);
});
app.post('/', (req, res) => {
phoneStates[i].contacts.push(req.body);
logPhoneState();
res.send("Ok");
});
app.listen(port);
}