-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
48 lines (41 loc) · 992 Bytes
/
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
const restify = require("restify");
const db = require("./db");
const config = require("./config");
const server = restify.createServer();
server.use(restify.plugins.queryParser());
const wrap = function (fn) {
return function (req, res, next) {
return fn(req, res, next).catch(function (err) {
return next(err);
});
};
};
server.get(
"/room",
wrap(async function (req, res, next) {
let rooms = await db.roomsDao.findAll();
res.send(rooms);
next();
})
);
server.get(
"/room/add",
wrap(async function (req, res, next) {
let roomId = parseInt(req.query.id, 10);
let room = await db.roomsDao.create(roomId);
res.send(room);
next();
})
);
server.get(
"/record",
wrap(async function (req, res, next) {
let records = await db.recordsDao.findAll();
res.send(records);
next();
})
);
server.listen(config.apiPort, function () {
console.log("%s listening at %s", server.name, server.url);
});
require("./monitor")();