-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
39 lines (31 loc) · 1.07 KB
/
routes.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
const devices = require('./controller/devices');
const words = require('./controller/words');
const sim = false;
module.exports = function(app){
//General Routes
app.get("/", function(req, res){
res.sendFile(__dirname + '/public/index.html');
});
//Devices Routes
app.post('/api/devices',devices.create);
app.get('/api/devices/',devices.readAll);
app.get('/api/devices/:name',devices.singleRead);
app.post('/api/renew/:name', devices.renew);
app.get('/api/update/:name',devices.verifyToken, devices.update);
app.get('/api/words/',words.readAll);
app.get('/api/w/',words.getData);
app.get('/api/populate',words.populateFromSheets);
setInterval(devices.checkStatus, 90000); // check every 1.5min 90000
// Handle 404
app.use(function(req, res) {
res.status(404);
res.json({"err":"404"});
});
// Handle 500
app.use(function(error, req, res, next) {
res.status(500);
res.json({"err":"500","error":error});
});
if(sim)
setInterval(devices.simulateNetwork, 2000);
}