/
express.js
44 lines (40 loc) · 911 Bytes
/
express.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
var express = require('express');
var app = express();
app.use(express.static('dist'));
app.get('/api/telephone', function (req, res) {
var telephonesArray = [{
id: 1,
telephone: "+7 999 99 99",
fullname: "Anakleto Anakletovich"
},{
id: 2,
telephone: "+7 888 88 88",
fullname: "Mikhail Smirnov"
},{
id: 3,
telephone: "+7 777 77 77",
fullname: "Andreas Rios"
}]
res.json(telephonesArray);
});
app.get('/api/telephone/:id', function (req, res) {
var id = req.params.id;
id = id - 1;
var phones = [{
id: 1,
telephone: "+7 999 99 99",
fullname: "Anakleto Anakletovich"
},{
id: 2,
telephone: "+7 888 88 88",
fullname: "Mikhail Smirnov"
},{
id: 3,
telephone: "+7 777 77 77",
fullname: "Andreas Rios"
}]
res.json(phones[id]);
});
app.listen(3002, function () {
console.log('Example app listening on port 3000!');
});